我按照mpdf文档mpdf E-mail a PDF file发送附件,并且我使用mailgun API发送邮件。
我的代码是
$header = "From: ".'donotreply@'.$domain." \r\n";
$header = "Subject: ".'My Subject'." \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$solution->user->id."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$solution->user->id."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $body."\r\n\r\n";
$header .= "--".$solution->user->id."\r\n";
$header .= "Content-Type: application/pdf; name=\"MySetSolution-".$solution->user->id.".pdf\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"MySetSolution-".$solution->user->id.".pdf\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$solution->user->id."--";
$mailgun->sendMessage($domain, array(
'from' => 'donotreply@'.$domain,
'to' => $email_address,
'subject' => 'My Subject',
'text' => $body
),
$header
);
我试过两个代码
$header .= 'Bcc: $emailList';
和
'bcc' => $email_address
但无法为密送收件人发送邮件。
如果可能的话,感谢您的任何想法。
答案 0 :(得分:0)
根据documentation,您应该能够在额外的数组中添加附件:
$result = $mgClient->sendMessage($domain, array(
'from' => 'Excited User <YOU@YOUR_DOMAIN_NAME>',
'to' => 'foo@example.com',
'cc' => 'baz@example.com',
'bcc' => 'bar@example.com',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!',
'html' => '<html>HTML version of the body</html>'
), array(
'attachment' => array('/path/to/file.txt', '/path/to/file.txt')
));
我认为你不能直接将它们添加到标题中,因为标题是在正文之前添加的。它可能会导致错误的电子邮件。