Monthly Archives: February 2014

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 https://developers.google.com/appengine/docs/php/mail/ 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" => "admin@example.com",
    "to" => "user@example.com",
    "subject" => "Your example.com account has been activated.",
    "textHTML" => $message_body
);

try {
    $message = new Message($mail_options);
    $message->send();
} 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.

When embedding YouTube videos, page jumps to the video

Ok. this is a problem I noticed today. Let me explain the situation,

I have embedded a YouTube video on one of my client websites. That video is placed at the end of the page. And when the page is loading the page jumps to that video instead of loading the page from the top. This is happening without me entering any anchor tags in the iframe of the YouTube embed code.

When checking the iframe code I noticed it is loading a # tag called #document within the iframe. This is causing the page to jump.

Solution,

Add following code to prevent #tag in iframe from loading on page load,

 style="display: none;" onload="this.style.display='block';"

Update

If your using WordPress this method is more suitable, Add the following code in the footer section. This will make the page jump back to top.

window.onload=function() {location.href='#';};