Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email with Mandrill using PHP

Tags:

php

mandrill

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' => '[email protected]',
    'from_name' => 'Sender person',
    'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
    'to' => array(array('email' => '[email protected]', 'name' => 'Recipient 1')),
    'merge_vars' => array(array(
        'rcpt' => '[email protected]',
        '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!

like image 832
James White Avatar asked Nov 01 '22 02:11

James White


1 Answers

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.

like image 153
James White Avatar answered Nov 15 '22 06:11

James White