Log in

View Full Version : How could I add SMTP Authentication into my email script



Ryan Fitton
08-18-2010, 12:20 PM
How could I add SMTP Authentication into my email script?

Basically this email script gets sent using PHP Mail() but i am wanting it to get sent by using googlemail's smtp outgoing mail servers instead, i have read up on this and i know it is possible.

Some examples are below:
http://www.codewalkers.com/c/a/Email-Code/Smtp-Auth-Email-Script/
http://support.webecs.com/KB/a390/php-mail-script-with-smtp-authentication.aspx

But i want to know how i could integrate it with the script i already have:

<?php

$to="ryan.fitton@googlemail.com";

$sub="Email From Website";

// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('Europe/London');

$Date = date("d M Y");

$Time = date("h:i A");

$msg .="
<html>
<body>
<p style='color:#000000;font-family:Helvetica,Arial,sans-serif;'>
You have received an automated email.
<br/><br/>
This message was sent on the $Date at $Time
<br/><br/>
--------------------------------------
<br/>
Message text goes here....
</p>
</body>
</html>
";

$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1' ;
$headers[] = 'From:ryan.fitton@googlemail.com';

// the implode is because each line has to be separated by an return space (part of the RFC)
$mail=mail($to,$sub,$msg, implode("\r\n", $headers));

if($mail)

{

echo "Mail successfully sent";

}

else

{

echo "Sorry could not sent";

}

?>

This email script that i already have is being automatically run every Friday by CRON.

djr33
08-18-2010, 02:48 PM
I would recommend creating a function that uses google called gmail() and defining that as you found in the examples. Then just replace mail() with gmail().