Php mailgun邮件附件无法在其他服务器上工作

Php mailgun邮件附件无法在其他服务器上工作,php,curl,mailgun,Php,Curl,Mailgun,当我在我的开发服务器上运行代码时,我使用mailgun库发送一封简单的邮件,一切看起来都很好,邮件是用附件发送的。但是当我上传到我的cpanel后运行相同的代码时,邮件发送时没有附件。任何帮助都将不胜感激。谢谢 //Call the function to send an email $subject='subject for mail'; $body='<b>Mail body</b>'; $email='joshiprakash9090@gmail.com';

当我在我的开发服务器上运行代码时,我使用mailgun库发送一封简单的邮件,一切看起来都很好,邮件是用附件发送的。但是当我上传到我的cpanel后运行相同的代码时,邮件发送时没有附件。任何帮助都将不胜感激。谢谢

//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);
}
?>
//调用函数发送电子邮件
$subject='subject for mail';
$body='Mail body';
$email='1joshiprakash9090@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功能用于发送带有附件的邮件。
函数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.$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_头,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_头,false);
$emailSetter=array('from'=>'UnitedChearleading',
'至'=>$至,
“主题”=>$subject,
“html”=>$body,
);
$i=0;
foreach($attachment作为$attache的附件)
{
$emailSetter['attachment['.$i.]']=$attach;
$i++;
}
curl_setopt($ch,CURLOPT_URL,$mg_message_URL);
curl_setopt($ch,CURLOPT_POSTFIELDS,$emailSetter);
$result=curl\u exec($ch);
打印(结果);
卷曲关闭($ch);
$res=json_decode($result,TRUE);
印刷品(港币);;
}
?>

我认为在发布问题之前,我没有正确地搜索堆栈溢出的解决方案,对此表示歉意

我只是改变了我的代码如下。
$attachment=array('@test.png','@test1.png')带有

$attachment=array('test.png','test1.png'); 

作为

这个问题看起来像是重复的,我从中找到了答案


第三个答案很好。

谢谢。我在Mailgun API版本3中遇到了这个问题。
foreach ($attachment as $attach)
    {
        $emailSetter['attachment['.$i.']']=$attach;
        $i++;

    }
 foreach ($attachment as $attach)
    {
        $emailSetter['attachment['.$i.']']=curl_file_create($attach);
        $i++;

    }