Skip to content

Instantly share code, notes, and snippets.

@lordspace
Last active November 6, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lordspace/83e9295b7196d4dc8f56 to your computer and use it in GitHub Desktop.
Save lordspace/83e9295b7196d4dc8f56 to your computer and use it in GitHub Desktop.
This is an sample php code that uses mandrill service to send emails. It uses PHPMailer. Here is an article how to do the setup: https://medium.com/@qsandbox/getting-started-with-mandrill-c2c3a6ba5c2a
<?php
// Author: Slavi Marinov | Orbisius.com & qSandbox.com
// 0) Read this article https://medium.com/@qsandbox/getting-started-with-mandrill-c2c3a6ba5c2a
// 1) Join Mandrill at http://mandrill.com/
// 2) Download PHPMailer from https://github.com/PHPMailer/PHPMailer
// Adapted example from: shared/PHPMailer-master/examples/mailing_list.phps
require_once 'shared/PHPMailer-master/class.phpmailer.php';
require_once 'shared/PHPMailer-master/class.smtp.php';
$message = "This is a test message prepared on: " . date( 'r' ) . " from " . $_SERVER['HTTP_HOST'] . ' ' . $_SERVER['REMOTE_ADDR'];
$mail = new PHPMailer;
$mail->addAddress( 'example_recipient@example.com', 'Example Name' );
$mail->Subject = "Testing Mandril: " . date('Y-m-d');
$mail->msgHTML($message);
$mail->Username = 'youremail@example.com';
$mail->Password = 'your_mandrill_api_key';
$mail->Host = 'smtp.mandrillapp.com';
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent, reduces SMTP overhead
$mail->Port = 587;
$mail->setFrom( 'mailer@' . $_SERVER['HTTP_HOST'], $_SERVER['HTTP_HOST'] );
//msgHTML also sets AltBody, but if you want a custom one, set it afterwards
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$sent_status = $mail->send() ? 1 : 0;
$result = "Send status: " . $sent_status;
if ( ! $sent_status ) {
$result .= " Error: " . $mail->ErrorInfo;
}
echo $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment