【问题标题】:How to set up these email headers with Mailgun API如何使用 Mailgun API 设置这些电子邮件标头
【发布时间】:2014-12-09 07:02:22
【问题描述】:

我正在使用 curl 和 PHP 来与 MailGun API 进行通信。 我有两封电子邮件,我需要我的收件人接收带有以下标题的电子邮件。 你能给我一个 curl (或 PHP 的 curl 库)中的示例代码 sn-p 来实现这些邮件标头吗?

-- 电子邮件 1--

From: "My Name"

Content-type: text/plain;charset="iso-8859-1"

Content-Transfer-Encoding: 8bit

-- 电子邮件 2--

MIME-Version: 1.0

From:my.domain.com <customerservice@mydomain.com>

Reply-To: my.domain.com <customerservice@mydomain.com>

Content-Type: multipart/alternative;boundary="=_730dc78ab764a3e997c2c451d9352d87"

Message-ID: <ndfmzn.jquf15@my.domain.com>

【问题讨论】:

    标签: php api email curl mailgun


    【解决方案1】:

    您可以在数组中添加任意数量的标题,只要它们以“h:”为前缀查看行

    'h:Message-Id'=>  'ndfmzn.jquf15@my.domain.com', //Your Message-ID
    

    下面是有关如何实现此功能的更详细说明:

    <?php
    $mg_api = 'key-XXX'; //YOUR API KEY
    $mg_version = 'api.mailgun.net/v2/'; //ROOT URL FOR MAILGUN
    $mg_domain = "samples.mailgun.org"; //YOUR DOMAIN AS SPECIFIED IN THE CONTROL PANEL
    $mg_from_email = "info@samples.com"; // YOUR FROM EMAIL
    $mg_reply_to_email = "info@samples.org"; // YOUR REPLY-TO EMAIL (USUALLY MATCHES FROM EMAIL)
    
    $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); 
    curl_setopt($ch, CURLOPT_URL, $mg_message_url);
    curl_setopt($ch, CURLOPT_POSTFIELDS,                
            array(  'from'      => 'you@domain.com',
                    'to'        => 'receiver@receiver.com',
                    'h:Reply-To'=>  ' <' . $mg_reply_to_email . '>',
                    'h:Message-Id'=>  'ndfmzn.jquf15@my.domain.com', //Your Message-ID
                    'subject'   => 'Hello',
                    'html'      => 'Mailgun POW POW!'
                ));
    $result = curl_exec($ch);
    curl_close($ch);
    $res = json_decode($result,TRUE);
    print_r($res);
    

    【讨论】:

    • 感谢您的回答。将 MIME-Version 标头传递给 Mailgun 是否可以?
    • 我从来没有具体尝试过,我认为没问题,但值得一试:)
    • 如何在 mailgun API 中设置标头?
    • 我在使用 Mailgun API 发送我的电子邮件的 HTML 部分时遇到问题,如下所示;这导致我的“移动”电子邮件响应视图出现问题: Content-Type: text/html; charset="ascii" Content-Transfer-Encoding:quoted-printable 那么我可以使用 Mailgun API 将其设置为“utf-8”吗? 'h:charset' => 'utf-8',谢谢!
    • @YesItsMe 不,无法找到解决方案。
    猜你喜欢
    • 2018-06-17
    • 2015-03-25
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多