我是StackOverflow的新手,因为我不会发布任何东西。如果我没有做好这件事,请原谅。
我找到了一篇文章,展示了如何在Codeigniter中集成Mailgun,它工作得很好。请查看此处- How to work with Mailgun API in CodeIgniter; Forbidden error in curl_exe()
当我想在同一段代码中附加一个pdf时,我的问题就来了。不是使用
$this->mailgun::send([
'from' => "Example.com team <no-reply@mg.example.com>",
'to' => "somerandomuser@gmail.com",
'subject' => "Welcome to Example.com",
'text' => "We just want to say hi. Have fun at Example.com"
]);
我曾希望用到以下几点:
$this->mailgun->send([
'from' => "Web Admin <postmaster@xxxxxx.xxxxxs.org>",
'to' => $toemail,
'subject' => $subj,
'text' => $bodtxt,
'html' => $bod,
'attachment' => curl_file_create($increport , 'application/pdf', $increportnm),
'h:Reply-To' => $replyname . ' <' . $replyemail . '>'
]);
其中$increport是我的pdf文件的路径,$increportnm是pdf文件的名称。
当我运行此命令时,没有任何电子邮件发布到Mailgun :(
有人能帮我吗?
发布于 2018-12-18 07:02:12
不需要调用curl_file_create...这是我从Codeigniter到Mailgun的方法,它是有效的:
$curl_post_data = array(
'from' => 'Emailer name <noreply@mailer.domain.com>',
'to' => $recipient,
'subject' => $subject,
'text' => $mailgun_text,
'html' => $mailgun_text_html,
'attachment' => @'filename.ext',
);
$service_url = 'https://api.mailgun.net/v3/mailer.mydomain.com/messages';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "api:xxxxxxxxxxxxxxxxxxx-xxxxxx-xxxxxx");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
之后,我运行$curl_response = curl_exec($curl);
并将响应解析为$response = json_decode($curl_response, true);
试试看。如果电子邮件不能发送出去,请尝试对$curl_response
执行print_r
,并检查邮件枪日志以了解其他故障信息
https://stackoverflow.com/questions/53822881
复制相似问题