首页 文章

PHP CURL不在电子邮件中发送附件

提问于
浏览
1

我使用 mailgun 发送电子邮件,附件没有通过电子邮件,工作

function send_mail($email,$subject,$msg) {
 $api_key="key-532cf742c1";/* Api Key got from https://mailgun.com/cp/my_account */

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
 curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$api_key);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
 curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/test.com/messages');
 curl_setopt($ch, CURLOPT_POSTFIELDS, array(
  'from' => 'Open <test@gmail.com>',
  'to' => $email,
  'subject' => $subject,
  'html' => $msg,
  'attachment'=>"/home/public_html/cms/upload/quiz.jpg"
));

 $result = curl_exec($ch);
 curl_close($ch);
 return $result;
 }

1 回答

  • 0
    $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$api_key);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/test.com/messages');
     curl_setopt($ch, CURLOPT_POSTFIELDS, array(
      'from' => 'Open <test@gmail.com>',
      'to' => $email,
      'subject' => $subject,
      'html' => $msg,
       'file'=>'@'.realpath('/home/test/Pictures/test.png')
    ));
    

    试试这个

相关问题