Last active
November 6, 2015 16:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( '[email protected]', 'Example Name' ); | |
$mail->Subject = "Testing Mandril: " . date('Y-m-d'); | |
$mail->msgHTML($message); | |
$mail->Username = '[email protected]'; | |
$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