5

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!

James White
  • 535
  • 10
  • 24
  • What is the result you get after uncommenting the print_r? – Morgan Mar 25 '14 at 22:34
  • Have you tried to debug at all? Have your checked you error logs? Have you checked your queue for sendmail (or whatever mechanism you server uses)? – Mike Brant Mar 25 '14 at 22:34
  • @Morgan I took the code on how to send using PHP from here: http://stackoverflow.com/questions/14473592/simple-php-function-to-send-an-email-with-mandrill/14486237#14486237 But I'm not using a template. So the print statement is commented out for now. – James White Mar 25 '14 at 22:58
  • @MikeBrant I'm not quite sure what kind of debugging to do. I put the echo in at the end to make sure something was happening. – James White Mar 25 '14 at 23:20
  • Now that you've figured out what you did, you should write what you did as an answer to your question and accept it as the correct answer. – Morgan Mar 26 '14 at 02:43

1 Answers1

2

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.

James White
  • 535
  • 10
  • 24
  • It would be helpful if you showed all of your code with the answer. Because you commented out print_r, I cannot tell why this is the fix as it would be commented out in your original code. – thatgibbyguy May 20 '14 at 19:52