當使用mailgun發送附件的郵件時,我正面臨問題。 如果有人做過這件事,請回復。 這是我的代碼...Mailgun發送郵件附附件
$mg_api = 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0';
$mg_version = 'api.mailgun.net/v2/';
$mg_domain = "samples.mailgun.org";
$mg_from_email = "[email protected]";
$mg_reply_to_email = "[email protected]";
$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 <' . '[email protected]' . '>',
'to' => '[email protected]',
'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);
(我用我的mailgun設置)
我收到的電子郵件沒有附件。如果我使用URL路徑,它會顯示URL而不是附件。
只是忘了@ ... thanx – TechCare99
你的例子需要作曲家 –
@ user1964269可以附件是直接鏈接而不是本地文件嗎?例如像'attachment [1]'=>'@http:// example.com/direc/file/path/file.jpg'? –