【发布时间】:2019-10-10 16:51:53
【问题描述】:
我正在尝试发送带有 pdf 附件的 php mailer 电子邮件并显示此错误: 电子邮件未发送。错误:SMTP 错误:数据未接受。SMTP 服务器错误:DATA END 命令失败详细信息:事务失败:缺少开始边界 SMTP 代码:554
我尝试在所有地方添加哑剧边界,但结果相同。
<?php
include dirname(__FILE__) . '/../views/pdf-receipt.php';
function sendMailTest(
$recipient_mail, $recipient_name, $from_mail, $from_name, $subject, $body, $body_without_html, $attachments=NULL
) {
require 'folder/PHPMailer-5.2.26/PHPMailerAutoload.php';
$mail = new PHPMailer;
try {
$mail->isSMTP();
$mail->setFrom($from_mail, $from_name);
$mail->addAddress($recipient_mail, $recipient_name);
$mime_boundary = "Name of company".md5(time());
$mail->SMTPDebug = true;
$mail->Host = 'email-smtp.eu-west-1.amazonaws.com';
$mail->Username = 'XXX';
$mail->Password = 'XXX';
$mail->Encoding = 'quoted-printable';
$mail->addCustomHeader('Content-ID', '20cca', 'Content-Type', 'multipart/mixed', 'boundary='.$mime_boundary.'\n');
$mail->Body = "--$mime_boundary\n";
$mail->CharSet = 'UTF-8';
$mail->Subject = utf8_encode($subject);
$mail->Body .= "Hey\n";
$mail->AltBody .= "--$mime_boundary\n".$body_without_html;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 000;
$mail->isHTML(true);
$data = '%PDF-1.2 6 0 obj << /S /GoTo /D (chapter.1) >>';
// if i comment line below email is sent properly,
// if i use AddAttachment local pdf file its working also,
// but i use TCPD generated PDF and attaching it, if i will
// just write it out to the message body i will see it as a
// text or if i will attach 'addStringEmbeddedImage' its
//displayed correctly but on same line as message text
// $attachments is pretty much this:
// $pdf->Output("test.pdf", "S");
// tried this $mail->Body .= "--$mime_boundary\n"; before next line
// did not help
$mail->AddStringAttachment($attachments, 'base64', 'application/pdf');
if($mail->send()) {
return;
}
} catch (Exception $e) {}
echo 'E-mail not sent. Error: ', $mail->ErrorInfo, PHP_EOL;
}
?>
我希望发送带有附件的电子邮件,但没有看到起始边界错误。
【问题讨论】:
标签: php amazon-web-services phpmailer php-5.2