So I've made a template called 'Basic' within Mandrill. I did a test send and it looks great. I put Mandrill into test mode and used the test API key in my code. I'm just trying to get the php to send out a test transactional email, but no email gets sent. Here is the printed response I get:
Array ( [0] => Array ( [email] => amiecrutchley02#gmail.com [status] => sent [_id] => 89bfab4c3938486eb9e36564f79a3e9f [reject_reason] => ) )
So I'm really not sure why I'm not receiving anything.
Here is my code:
<?php
require_once('includes/mandrill/Mandrill.php');
$mandrill = new Mandrill('my_api_key');
$message = array(
'subject' => 'Thank You For Your Purchase',
'from_email' => 'no-reply#acq.com',
'from_name' => 'ACQ',
'to' => array(array('email' => 'amiecrutchley02#gmail.com', 'name' => 'Amie')),
'merge_vars' => array(array(
'rcpt' => 'amiecrutchley02#gmail.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Amie'),
array(
'name' => 'LASTNAME',
'content' => 'Crutchley')
))));
$template_name = 'Basic';
$template_content = array(
array(
'name' => 'main',
'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, your profile has been updated!'),
array(
'name' => 'footer',
'content' => 'ACQ, Copyright 2014')
);
$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
print_r($response);
?>
a test API key is specifically designed to not send email. It's designed so you can mimic sending email, but doesn't actually send. You're also not charged for sending tests. Here's the Mandrill KB about what test mode is, and how it works: Does Mandrill have a test mode or sandbox?
Well, weird, but my test API was the problem. I tried the public API and boom! It works!
Related
I am creating issue by using kbsali redmine api, I am receiving subject can not be blank error even I am passing subject
$result=$client->issue->create([
'project_id' => 'projder',
'subject' => 'this is subject subject this is subject subject this is subject subject this is subject subject this is subject subject',
'description' => 'this is subject subject this is subject subject this is subject subject this is subje',
'assigned_to_id' => '45',
'priority_id' => $_POST['inputPriority'],
'uploads' => array(
array(
'token' => $upload->upload->token,
'filename' => $file,
'description' => 'This is my file description',
'content_type'=> 'image/png'
),
array(
'token' => $uploadoptional->upload->token,
'filename' => $optionalUpload,
'description' => 'Client Attachment',
'content_type'=> $optionalUploadType
)
)
]);
)
SimpleXMLElement Object
(
[#attributes] => Array
(
[type] => array
)
[error] => Subject cannot be blank
)
I found the solution, redmine subject field rights were not given to the user by using i was sending API request to create ticket.
I guess there is a issue with Mandrill attachments x Hotmail/Outlook.com.
I can send e-mail attachments with Mandrill using base64_encode(). I am using the PHP library.
If I send an e-mail to Gmail or any other provider, the attachment looks fine. Downloading it and opening normally.
But sending to a Hotmail/Outlook.com, the attachments came with no extension/file format. By downloading, it can only be opened by adding the extension manually (for example, .pdf).
The code:
$file_data = file_get_contents($_FILES["test_file"]["tmp_name"])
$file_type = $_FILES["test_file"]["type"]
$mandrill = new Mandrill('MANDRILL_API_KEY_HERE');
$message = array(
'html' => $html,
'subject' => 'Testing',
'from_email' => 'sender#test.com',
'from_name' => 'Sender',
'attachments' => array(
array(
'name' => 'Test PDF document',
'type' => $file_type,
'content' => base64_encode($file_data)
)
),
'to' => array(
array(
'email' => 'to#test.com',
'name' => 'John Doe',
'type' => 'to'
)
),
'headers' => array('Reply-To' => 'sender#test.com')
);
$result = $mandrill->messages->send($message);
Any ideas? Is it a Mandrill or Hotmail issue?
Thanks!
I have found the solution. Gmail and other email services recognizes the type attribute as above, but Hotmail only recognizes the file type by adding the extension to the attachment name (name attribute).
For example:
'name' => 'Test PDF document.pdf',
It look obvious, but Hotmail requires it. Sharing my simple knowledge, since I received no answers.
This issue really driving me crazy this past hours. Why is the email that send with Mandrill not showing the right information about the Cc email address.
So for example, I want to send email to
receiver_to_a#mail.com
receiver_cc_a#mail.com
receiver_cc_b#mail.com
When I see the email header on receiver_cc_a#mail.com. its always show no cc, and that email is send "to" receiver_cc_a#mail.com, not as cc
Is anyone having the same problem? I already try sending email in PHP with PhpMailer and also try from the PHP API from Mandrill itself but no luck.
You need to set the option preserve_recipients to true.
$message = array(
'html' => '<p>Example HTML content</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'message.from_email#example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
),
array(
'email' => 'ccrecipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'cc'
)
),
'headers' => array('Reply-To' => 'message.reply#example.com'),
'preserve_recipients' => true
);
I am sending email using merge_vars for dynamic contents. Here is how my merge_vars look like:
$message['merge_vars'][$index] = array(
'rcpt' => $email,
'vars' => array(
array(
'name' => 'url',
'content' => $url
),
array(
'name' => 'sname',
'content' => $sname
),
array(
'name' => 'lname',
'content' => $lname,
),
array(
'name' => 'email',
'content' => $email
)
),
);
Everything is working fine. But when same recipient should receive multiple different email in a single API call, then the problem occurs. That time same recipient don't receive different email, he receives same email multiple times.
In a single api call you cannot send different emails to same email address with different merge vars.
You need to fire multiple api calls having target recipient in each call with respective merge_vars to meet your requirement.
I'm trying to send email using Mandrill and PHP and I can't get it to send.
I've downloaded the PHP API wrapper from here:https://packagist.org/packages/mandrill/mandrill
Mandrill.php is in my root and the Mandrill folder is in the same directory.
Here's my code:
<?php
require_once 'Mandrill.php';
$mandrill = new Mandrill('MY API KEY IS USUALLY HERE');
$message = array(
'subject' => 'Test message',
'from_email' => 'jwjody#yahoo.com',
'from_name' => 'Sender person',
'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
'to' => array(array('email' => 'jwjody#yahoo.com', 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))));
//print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
echo ("hello");
?>
But it won't send. I'm not sure where the failure is. Is it something obvious I'm missing?
I see the issue now.
I see what's going on now!
I changed
$mandrill->messages->sendTemplate($template_name, $template_content, $message));
to
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
And it works!
Instead of calling the sendTemplate() function I should have used
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
Once I changed the function call the mail was sent.