1
開発サーバーでコードを実行したときに、すべてがうまく見えてメールが添付ファイルと共に送信されている場合、mailgunライブラリを使用して簡単なメールを送信します。しかし、私のcpanelにアップロードした後に同じコードを実行すると、メールは添付ファイルなしで送信されます。どんな助けもありがとう。ありがとうメールサーバーの添付ファイルが別のサーバーで動作していません
//Call the function to send an email
$subject='subject for mail';
$body='<b>Mail body</b>';
$email='[email protected]';
//$attachment=array('@/home/unitedd5/public_html/beta/upload/VIBES.png','checkbox.htm');
$attachment=array('@test.png','@test1.png');
sendmail($email, $subject, $body,$attachment);
//MailGun function to send mail with attacment.
function sendmail($to, $subject, $body,$attachment) {
$mg_api = 'key-mykey';
$mg_version = 'api.mailgun.net/v2/';
$mg_domain = "mydomain";
$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($ch, CURLOPT_HEADER, false);
$emailSetter=array('from' => 'Unitedcheerleading <' . '[email protected]' . '>',
'to' => $to,
'subject' => $subject,
'html' => $body,
);
$i=0;
foreach ($attachment as $attach)
{
$emailSetter['attachment['.$i.']']=$attach;
$i++;
}
curl_setopt($ch, CURLOPT_URL, $mg_message_url);
curl_setopt($ch, CURLOPT_POSTFIELDS,$emailSetter);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
$res = json_decode($result, TRUE);
print_r($res);
}
?>
ありがとうございます。 Mailgun APIバージョン3でこの問題が発生しました。 – WhereDidMyBrainGo