Created
February 28, 2012 16:23
-
-
Save brandonmwest/1933453 to your computer and use it in GitHub Desktop.
Testing WP integration
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 | |
include_once "lib/swift_required.php"; | |
/* | |
* Create the body of the message (a plain-text and an HTML version). | |
* $text is your plain-text email | |
* $html is your html version of the email | |
* If the reciever is able to view html emails then only the html | |
* email will be displayed | |
*/ | |
$text = "Hi!\nHow are you?\n"; | |
$html = <<<EOM | |
<html> | |
<head></head> | |
<body> | |
<p>Hi!<br> | |
How are you?<br> | |
</p> | |
</body> | |
</html> | |
EOM; | |
// This is your From email address | |
$from = array('yourcompany@yourcompany.com' => 'Name To Appear'); | |
// Email recipients | |
$to = array( | |
'destination1@example.com'=>'Destination 1 Name', | |
'destination2@example.com'=>'Destination 2 Name' | |
); | |
// Email subject | |
$subject = 'Example PHP Email'; | |
// Login credentials | |
$username = 'yoursendgridusername'; | |
$password = 'yourpassword'; | |
// Setup Swift mailer parameters | |
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587); | |
$transport->setUsername($username); | |
$transport->setPassword($password); | |
$swift = Swift_Mailer::newInstance($transport); | |
// Create a message (subject) | |
$message = new Swift_Message($subject); | |
// attach the body of the email | |
$message->setFrom($from); | |
$message->setBody($html, 'text/html'); | |
$message->setTo($to); | |
$message->addPart($text, 'text/plain'); | |
// send message | |
if ($recipients = $swift->send($message, $failures)) | |
{ | |
// This will let us know how many users received this message | |
echo 'Message sent out to '.$recipients.' users'; | |
} | |
// something went wrong =( | |
else | |
{ | |
echo "Something went wrong - "; | |
print_r($failures); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment