简体   繁体   English

使用mailgun和附加的mpdf文件将邮件发送到密件抄送

[英]send mail to bcc with mailgun with attached mpdf file

I'm sending attachment by following mpdf documentation mpdf E-mail a PDF file , and i'm using mailgun API to send mails. 我通过遵循mpdf文档mpdf发送附件,通过电子邮件发送PDF文件 ,并且我正在使用mailgun API发送邮件。

My Code is 我的代码是

$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
            );

I hv tried both code 我试过两个代码

$header .= 'Bcc: $emailList';

and

'bcc' => $email_address

but unable to send mail for bcc recipients. 但无法为密件抄送收件人发送邮件。

Thanks for any idea if possible. 如果有任何想法,谢谢您。

According to the documentation you should be able to add attachments in an extra array: 根据文档,您应该能够在额外的阵列中添加附件:

$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')
));

I don't think you can add them directly to the header, since the header is added before the body. 我认为您不能将它们直接添加到标题中,因为标题是在正文之前添加的。 It will probably result in an incorrect email. 可能会导致发送不正确的电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM