I am sending a simple mail using mailgun library when i runs the code on my development server than everything looks fine and mail is sending with attachment. But when i run same code after uploading to my cpanel the mail is sending without attachment. any help would be appreciated. Thanks
//Call the function to send an email
$subject='subject for mail';
$body='<b>Mail body</b>';
$email='joshiprakash9090@gmail.com';
//$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 <' . 'sales@unitedcheerleading.com' . '>',
'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);
}
?>