<?php
include_once "lib/swift_required.php";
$subject = 'Hello from Mandrill, PHP!';
$from = array($_POST['email'] => $_POST['name']);
$to = array(
'dostalcody@gmail.com' => 'Cody Dostal'
);
$text = $_POST['message'];
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
$transport->setUsername('[username_redacted]');
$transport->setPassword('[secret_key_redacted]');
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($text, 'text/plain');
$message->setTo($to);
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
?>
<?php
try {
$mandrill = new Mandrill('[secret_key_redacted');
$message = array(
'text' => $_POST['message'],
'subject' => 'example subject',
'from_email' => 'dostalcody@gmail.com',
'from_name' => 'Cody Dostal',
'to' => array(
array(
'email' => $_POST['email'],
'name' => $_POST['name'],
'type' => 'to'
)
),
'headers' => array('Reply-To' => 'dostalcody@gmail.com.com'),
);
$async = false;
$result = $mandrill->messages->send($message, $async, $ip_pool, $send_at);
print_r($result);
} 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_Subaccount - No subaccount exists with the id 'customer-123'
throw $e;
}
?>