时对此进行了测试
我一直在尝试发送一封带有pdf附件的电子邮件。我正在使用PHPMailer,但我似乎无法管理它。我已经尝试了大量不同的附件方法,也尝试了不同的文件路径。下面是代码:
require_once ("class.phpmailer.php");
$lc_name = $_SESSION['lc_name'];
$filename = "email_attachment/".$lc_id.".pdf";
require_once ("func_ui.php");
$vou_mail = func_ui::select_mail($lc_id, 3);
if($vou_mail["auto"] == 0)
{
return;
}
else
{
$custom_body = $vou_mail["body"];
}
$body = "Dear customer,<br><br>
$custom_body<br><br>
Kind Regards,<br><br>
$gm_name<br>
Centre Manager";
$mail = new PHPMailer();
try {
$mail->IsSMTP();
$mail->Host = "****"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Port = ***; // set the SMTP port for the GMAIL server
$mail->Username = "******"; // GMAIL username
$mail->Password = "****"; // GMAIL password
$from_name = '***';
$subject = '';
//$mail->AddAttachment($filename, "", "base64", "application/pdf");
//$mail->AddAttachment(realpath('./email_attachment/1220.pdf'),'1220.pdf','base64', 'application/pdf');
$mail->SetFrom('info@***.com', "");
$mail->AddReplyTo("info@***.com", "");
$mail->Subject = "$lc_name - Voucher.";
//$mail->IsHTML(false);
$reason = $mail->addAttachment("/email_attachment/1220.pdf");
$mail->AltBody = "To view the message, please use an HTML compatible m_email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($email_v, "");
if ($reason == false){
echo "Didn't like this linen";
}
else
{
echo "worked ?";
}
if(! $mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
其中有以下行:
$reason = $mail->addAttachment("/email_attachment/1220.pdf");
试着把它改成:
$mail->addAttachment('/email_attachment/1220.pdf','1220.pdf');
您有想要附加的PDF的路径,但还需要再次提供它的文件名。我在试验其他PHPmailer函数