代码之家  ›  专栏  ›  技术社区  ›  Nageen

yii2 mandrill电子邮件软验证

  •  -2
  • Nageen  · 技术社区  · 8 年前

    我正在使用yii2插件 镍铬合金 我想知道,电子邮件的状态就像是软验证或者电子邮件是否已发送。有人能帮我吗?是吗?

    事先谢谢。

    \Yii::$app->mailer
    ->compose('mailViewName', ['model' => $model])
    ->setTo('email@email.com')
    ->send();
    
    3 回复  |  直到 8 年前
        1
  •  0
  •   user7961310    8 年前

    你能试试吗?它对我很有用。

        echo "<pre>";
        print_r(Yii::$app->mailer->getLastTransaction());die;
    

    输出为:

    Array
    (
        [0] => Array
            (
                [email] => tets.test@gmail.comm
                [status] => rejected
                [_id] => abcabcabacbac
                [reject_reason] => soft-bounce
            )
    
    )
    
        2
  •  1
  •   Muhammad Omer Aslam    8 年前

    Mandrill以每条消息为基础跟踪电子邮件,因此通过您的帐户发送的单个电子邮件会跟踪打开、单击和发送数据。您可以添加标签和元数据,为您发送的电子邮件提供进一步的上下文。

    消息API

    mandrill会自动索引一些字段,您可以使用这些字段搜索或查找与发送相关的有趣趋势。搜索在Web应用程序中可用,并通过 Messages-API .

    所以您需要研究消息API /messages/info.json ,检索最近发送的单个消息的信息。当你发送一条消息时,曼得利尔的回答是

    Array
    (
        [0] => Array
            (
                [email] => recipient.email@example.com
                [status] => sent
                [reject_reason] => hard-bounce
                [_id] => abc123abc123abc123abc123abc123
            )
    
    )
    

    这个 _id=>abc123abc123abc123abc123abc123 可通过向 messages/info.json 提供了易于转换为yii2的PHP示例代码。见下文

    <?php
    try {
        $mandrill = new Mandrill('YOUR_API_KEY');
        $id = 'abc123abc123abc123abc123';
        $result = $mandrill->messages->info($id);
        print_r($result);
        /*
        Array
        (
            [ts] => 1365190000
            [_id] => abc123abc123abc123abc123
            [sender] => sender@example.com
            [template] => example-template
            [subject] => example subject
            [email] => recipient.email@example.com
            [tags] => Array
                (
                    [0] => password-reset
                )
    
            [opens] => 42
            [opens_detail] => Array
                (
                    [0] => Array
                        (
                            [ts] => 1365190001
                            [ip] => 55.55.55.55
                            [location] => Georgia, US
                            [ua] => Linux/Ubuntu/Chrome/Chrome 28.0.1500.53
                        )
    
                )
    
            [clicks] => 42
            [clicks_detail] => Array
                (
                    [0] => Array
                        (
                            [ts] => 1365190001
                            [url] => http://www.example.com
                            [ip] => 55.55.55.55
                            [location] => Georgia, US
                            [ua] => Linux/Ubuntu/Chrome/Chrome 28.0.1500.53
                        )
    
                )
    
            [state] => sent
            [metadata] => Array
                (
                    [user_id] => 123
                    [website] => www.example.com
                )
    
            [smtp_events] => Array
                (
                    [0] => Array
                        (
                            [ts] => 1365190001
                            [type] => sent
                            [diag] => 250 OK
                        )
    
                )
    
        )
        */
    } catch(Mandrill_Error $e) {
        // Mandrill errors are thrown as exceptions
        echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
        // A mandrill error occurred: Mandrill_Unknown_Message - No message exists with the id 'McyuzyCS5M3bubeGPP-XVA'
        throw $e;
    }
    ?>
    

    Web挂钩

    你也可以在你的mandrill帐户上设置webhook,并指向你的服务器页面说 yoursite.com/mandrill-webhook 在创建Webhook时,您可以指定哪些事件将触发该Webhook,选择 send ,请 open ,请 click 并立即保存,只要这些事件中的任何一个将触发,它将发布一个数组 json 这说明哪一个触发了。当您第一次设置Webhook时,您可以向您的URL发送一个测试调用,该URL将按如下方式发布所有3个事件。

    Array
    (
        [mandrill_events] => [
      {
        "event": "send",
        "msg": {
          "ts": 1365109999,
          "subject": "This an example webhook message",
          "email": "example.webhook@mandrillapp.com",
          "sender": "example.sender@mandrillapp.com",
          "tags": [
            "webhook-example"
          ],
          "opens": [],
          "clicks": [],
          "state": "sent",
          "metadata": {
            "user_id": 111
          },
          "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
          "_version": "exampleaaaaaaaaaaaaaaa"
        },
        "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
        "ts": 1530365793
      },
      {
        "event": "open",
        "msg": {
          "ts": 1365109999,
          "subject": "This an example webhook message",
          "email": "example.webhook@mandrillapp.com",
          "sender": "example.sender@mandrillapp.com",
          "tags": [
            "webhook-example"
          ],
          "opens": [
            {
              "ts": 1365111111
            }
          ],
          "clicks": [
            {
              "ts": 1365111111,
              "url": "http://mandrill.com"
            }
          ],
          "state": "sent",
          "metadata": {
            "user_id": 111
          },
          "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
          "_version": "exampleaaaaaaaaaaaaaaa"
        },
        "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
        "ip": "127.0.0.1",
        "location": {
          "country_short": "US",
          "country": "United States",
          "region": "Oklahoma",
          "city": "Oklahoma City",
          "latitude": 35.4675598145,
          "longitude": -97.5164337158,
          "postal_code": "73101",
          "timezone": "-05:00"
        },
        "user_agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100317 Postbox/1.1.3",
        "user_agent_parsed": {
          "type": "Email Client",
          "ua_family": "Postbox",
          "ua_name": "Postbox 1.1.3",
          "ua_version": "1.1.3",
          "ua_url": "http://www.postbox-inc.com/",
          "ua_company": "Postbox, Inc.",
          "ua_company_url": "http://www.postbox-inc.com/",
          "ua_icon": "http://cdn.mandrill.com/img/email-client-icons/postbox.png",
          "os_family": "OS X",
          "os_name": "OS X 10.6 Snow Leopard",
          "os_url": "http://www.apple.com/osx/",
          "os_company": "Apple Computer, Inc.",
          "os_company_url": "http://www.apple.com/",
          "os_icon": "http://cdn.mandrill.com/img/email-client-icons/macosx.png",
          "mobile": false
        },
        "ts": 1530365793
      },
      {
        "event": "click",
        "msg": {
          "ts": 1365109999,
          "subject": "This an example webhook message",
          "email": "example.webhook@mandrillapp.com",
          "sender": "example.sender@mandrillapp.com",
          "tags": [
            "webhook-example"
          ],
          "opens": [
            {
              "ts": 1365111111
            }
          ],
          "clicks": [
            {
              "ts": 1365111111,
              "url": "http://mandrill.com"
            }
          ],
          "state": "sent",
          "metadata": {
            "user_id": 111
          },
          "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa2",
          "_version": "exampleaaaaaaaaaaaaaaa"
        },
        "_id": "exampleaaaaaaaaaaaaaaaaaaaaaaaaa2",
        "ip": "127.0.0.1",
        "location": {
          "country_short": "US",
          "country": "United States",
          "region": "Oklahoma",
          "city": "Oklahoma City",
          "latitude": 35.4675598145,
          "longitude": -97.5164337158,
          "postal_code": "73101",
          "timezone": "-05:00"
        },
        "user_agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100317 Postbox/1.1.3",
        "user_agent_parsed": {
          "type": "Email Client",
          "ua_family": "Postbox",
          "ua_name": "Postbox 1.1.3",
          "ua_version": "1.1.3",
          "ua_url": "http://www.postbox-inc.com/",
          "ua_company": "Postbox, Inc.",
          "ua_company_url": "http://www.postbox-inc.com/",
          "ua_icon": "http://cdn.mandrill.com/img/email-client-icons/postbox.png",
          "os_family": "OS X",
          "os_name": "OS X 10.6 Snow Leopard",
          "os_url": "http://www.apple.com/osx/",
          "os_company": "Apple Computer, Inc.",
          "os_company_url": "http://www.apple.com/",
          "os_icon": "http://cdn.mandrill.com/img/email-client-icons/macosx.png",
          "mobile": false
        },
        "url": "http://mandrill.com",
        "ts": 1530365793
      }]
    )
    
        3
  •  0
  •   Muhammad Omer Aslam    8 年前

    这可以通过在发送前设置头来完成。

    您要查找的标题是:x-mc-track

    阅读文档 here

    你可以让他们

    $message = Yii::$app->mailer->compose(...);
    $message->getSwiftMessage()->getHeaders()->addTextHeader('X-MC-Track', 'opens,clicks');
    

    也许它需要一些测试和调整,你应该使用loca测试smtp服务器,比如 https://mailcatcher.me/ 这将帮助您检查是否正在设置这些头文件。

    推荐文章