addAttachment不会向电子邮件添加任何附件



我已经写好了以下代码,电子邮件发送良好,但我一直无法弄清楚为什么电子邮件不包括预期的附件(pdf文件(。

我还尝试了$mail->attach with MIME,结果出现了500内部服务器错误。

$pdf = public_path() . '/assets/attachments/TermSheet.pdf';
$mail = new PHPMailerPHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPSecure = '';
$mail->SMTPAuth = true;
$mail->IsHTML(true);
//ENV VARIABLES
$mail->Host =  env("MAIL_HOST");
$mail->Port = env("MAIL_PORT");
$mail->Username = env("MAIL_USERNAME");
$mail->Password = env("MAIL_PASSWORD");
$mail->SetFrom($fromemail, $fromname);
$mail->Subject = $emailsubject;
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = $emailsubject;
$mail->addAttachment($pdf);
$mail->Body    = $initbody;  
$mail->AddAddress($user);
if(isset($ccemaillist)){                        //cc
$ccemail = explode(";",$ccemaillist);
foreach ($ccemail as $toccmail) {
$mail->AddAddress($toccmail);
}
}                  
if($mail->Send()) {    
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $currentapp.'/mail/send?api_user_id='.$creatorid);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"recipient_email=$user&email_type=WelcomeEmail&sys_status=1&creator=$creatorid");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);     
return "SUC";
}

我不确定为什么它不起作用,如果有任何意见,我将不胜感激。提前感谢:(

它可能会给出

500内部服务器错误

由于文件路径不正确。

你可以试着$pdf = asset('assets/attachments/TermSheet.pdf');public_path((在某些情况下不起作用。

相关内容

  • 没有找到相关文章

最新更新