Sending Emails With Google App Engine PHP

So here are some tips on how to send email using PHP on Google App Engine. This basically covers how I overcame the problems when I tried to implement this.

Check before starting to read my version.

Sending HTML – Use htmlBody in the mail options to include the message body this will preserve your html code. other wise it will just print the html code out.

require_once 'google/appengine/api/mail/Message.php';

use google\appengine\api\mail\Message; // make sure this is at top of the page

// ...

$message_body = "...";

$mail_options = (
    "sender" => "",
    "to" => "",
    "subject" => "Your account has been activated.",
    "textHTML" => $message_body

try {
    $message = new Message($mail_options);
} catch (InvalidArgumentException $e) {


including the Message.php file – If you include the use statement partway down the page it will not work. I had a hard time figuring this out but just php common sense. Make sure you add the use statement on the top of the page before any php code. Then you will be fine.

Also make sure the from address is a Google Apps for Business Account, then things are just plain easy.