Tec*_*e99 10 php email email-attachments mailgun
当邮件有使用mailgun发送的附件时,我正面临问题.如果有人做过这件事,请回复.这是我的代码......
$mg_api = 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0';
$mg_version = 'api.mailgun.net/v2/';
$mg_domain = "samples.mailgun.org";
$mg_from_email = "info@samples.com";
$mg_reply_to_email = "info@samples.org";
$mg_message_url = "https://".$mg_version.$mg_domain."/messages";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $mg_api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $mg_message_url);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array( 'from' => 'aaaa <' . 'aaa@aaa.com' . '>',
'to' => 'test.client91@gmail.com',
'h:Reply-To'=> ' <' . $mg_reply_to_email . '>',
'subject' => 'aaaaa'.time(),
'html' => 'aaaaaa',
'attachment'[1] => 'aaa.rar'
));
$result = curl_exec($ch);
curl_close($ch);
$res = json_decode($result,TRUE);
print_r($res);
Run Code Online (Sandbox Code Playgroud)
(我使用过我的mailgun设置)
我收到没有附件的电子邮件.如果我使用URL路径,则显示URL而不是附件.
小智 7
我意识到这已经老了,但我刚遇到这个问题,这个页面几乎是我能在网上找到的唯一信息.所以我希望这会帮助别人.在与MailGun支持人员交谈之后,我发现以下适用于当前的API.
循环遍历零到n个附件文件的数组:
$attachmentsArray = array('file1.txt', 'file2.txt');
$x = 1;
foreach( $attachmentsArray as $att )
{
$msgArray["attachment[$x]"] = curl_file_create( $att );
$x ++;
}
// relevant cURL parameter, $msgArray also contains to, from, subject parameters etc.
curl_setopt($ch, CURLOPT_POSTFIELDS,$msgArray);
Run Code Online (Sandbox Code Playgroud)
小智 5
您需要以下列方式更改最后一个参数:
attachment[1]' => '@aaa.rar
我们在这个用例的文档中有一些示例.只需单击顶部栏中的PHP即可切换语言. http://documentation.mailgun.net/user_manual.html#examples-sending-messages-via-http
如有任何问题,请随时向我们发送电子邮件至support@mailgunhq.com.我们总是很乐意提供帮助.
| 归档时间: |
|
| 查看次数: |
22714 次 |
| 最近记录: |