Yii2 Mandrill email soft verification

Multi tool use
Yii2 Mandrill email soft verification
i am using yii2 plugin nickcv and i want to know that email status just like soft verification or email delivered or not. can anyone help me??
Thanks in advance.
Yii::$app->mailer
->compose('mailViewName', ['model' => $model])
->setTo('email@email.com')
->send();
It's provide by mandrill
– nageen nayak
Jun 30 at 2:15
3 Answers
3
Can you try it. it works for me..!
echo "<pre>";
print_r(Yii::$app->mailer->getLastTransaction());die;
output will be :-
Array
(
[0] => Array
(
[email] => tets.test@gmail.comm
[status] => rejected
[_id] => abcabcabacbac
[reject_reason] => soft-bounce
)
)
amazing, i just want it.
– nageen nayak
2 days ago
Mandrill tracks emails on a per-message basis, so opens, clicks and delivery data are tracked for individual emails sent through your account. You can add tags and metadata to give further context to the emails you send.
Mandrill automatically indexes a number of fields that you can use to search or find interesting trends relevant to your sending. Searching is available in the web application and via the Messages-API
.
Messages-API
So you need to look into Messages API /messages/info.json
, which retrieves the information for a single recently sent message. When you send a message mandrill responses with
/messages/info.json
Array
(
[0] => Array
(
[email] => recipient.email@example.com
[status] => sent
[reject_reason] => hard-bounce
[_id] => abc123abc123abc123abc123abc123
)
)
the _id=>abc123abc123abc123abc123abc123
can be used to check the status of the email by sending a call to the messages/info.json
, php sample code is provided that can be easily converted to Yii2. see below
_id=>abc123abc123abc123abc123abc123
messages/info.json
<?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;
}
?>
Also you can setup WebHooks on you mandrill account and point it to your servers page say yoursite.com/mandrill-webhook
and while creating the webhook you can specify which events would trigger this webhook, select send
, open
, click
and save now whenever any of these events will trigger it will post an array with json
that tells which even triggered. When you will setup the webhook for the first time you can send a test call to your url which will post all 3 of these events in like below.
yoursite.com/mandrill-webhook
send
open
click
json
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
}]
)
i think its code for core php not for yii2 and its work in core php but not in yii2
– nageen nayak
2 days ago
i dont find your reason strong enough, as there is no php code that wont run in Yii, the only thing to change would be namespaces
Mandril
to Mandrill
@nageennayak– Muhammad Omer Aslam
2 days ago
Mandril
Mandrill
This can be accomplished by setting headers before sending.
The header you are looking for will be : X-MC-Track
Read documentation here
And you will be able to set them by
$message = Yii::$app->mailer->compose(...);
$message->getSwiftMessage()->getHeaders()->addTextHeader('X-MC-Track', 'opens,clicks');
Maybe it needs some test and tweaking you should use a loca testing smtp server like https://mailcatcher.me/ that will help you checking that those headers are being set.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is "soft verification"?
– rob006
Jun 29 at 15:26