繁体   English   中英

使用Mailgun API和PHP cURL发送时如何包含嵌入式图像

[英]How do I include in-line images when sending with Mailgun API and PHP cURL

我一直在寻找有关如何使用Mailgun API和标准PHP cURL在电子邮件中发送嵌入式图像的线索- 不是使用Mailgun SDK的 ,也没有运气,所以我不得不提出这个问题。

到目前为止,这是我的代码:

$url    = 'https://api:**my-key**@api.eu.mailgun.net/v3/**my-domain.com**/messages';
$from   = 'Admin < admin@my-domain.com >';
$to     = 'Excite User < user@somewhere.com >';

$subject= 'Excite Stuff In Here';
$body   = '<html>
    <img src="cid:logo_sml.png">
    <p>Testing Mailgun API with inline images</p>
</html>';
$text   = strip_tags( nl2br($body) );

$tag    = 'Test';

$inline = ['inline' =>  realpath('../includes/images/logo_sml.png')];

// parameters of message
$params = [
    'from'      => $from,
    'to'        => $to,
    'subject'   => $subject,
    'text'      => $text,
    'html'      => $body,
    'inline'    => json_encode($inline),
    'o:tag'     => $tag
];

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params );

$data_results = curl_exec($curl);

$response = json_decode($data_results);

curl_close($curl);

电子邮件已发送,没有任何错误消息,但是没有任何图像(内联或附件)。 我要去哪里错了?

我向Mailgun支持人员提出了要求,Marco给出了一个解决方案,我认为我会分享:

$inline = curl_file_create(realpath('../includes/images/logo_sml.png'));
...
'inline'    => $inline,

curl_file_create —创建一个CURL文件对象以附加图像。 其余代码保持不变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM