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