首页 > 其他 > 详细

使用 Mailgun 实现 带附件的Email 发送功能

时间:2017-02-09 13:56:55      阅读:924      评论:0      收藏:0      [点我收藏+]

Mailgun API 官方文档:https://documentation.mailgun.com/user_manual.html#introduction

注册Mailgun 并根据流程获取 Domain(service_url)  和 api_key

然后就只需编写以下代码即可了

 1 //附件
 2 $filePath=‘@../upload/pdf/20170209094311.pdf‘;  
 3 
 4 $curl_post_data=array(
 5     ‘from‘    => ‘***@***.com‘,
 6     ‘to‘      => ‘***@***.com‘,
 7     // ‘bcc‘     => ‘‘
 8     ‘subject‘ => ‘Hello‘,
 9     ‘text‘    => ‘test‘,
10     ‘html‘      => ‘<h1>Hello Word!</h1>‘,
11 ‘attachment[1]‘ => $filePath
12 );
13 
14 $service_url = ‘https://api.mailgun.net/v3/mg.*****.com/messages‘;
15 $curl = curl_init($service_url);
16 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
17 curl_setopt($curl, CURLOPT_USERPWD, "api:key-************"); 
18 
19 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
20 curl_setopt($curl, CURLOPT_POST, true);
21 
22 curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
23 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
24 
25 
26 $curl_response = curl_exec($curl);
27 $response = json_decode($curl_response);
28 curl_close($curl);
29 
30 var_dump($response);

 

使用 Mailgun 实现 带附件的Email 发送功能

原文:http://www.cnblogs.com/lishalom/p/6381549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!