Monday, February 22, 2010

Sending emails with Gmail smtp server rather than your server's smtp

Download the phpmailer classes At http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/

Then use the below code to send emails.
require(“includes/class.phpmailer.php”);
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = ’ssl://smtp.gmail.com:465′;
$mailer->SMTPAuth = TRUE;
$mailer->Username = ‘{somename}@gmail.com’; // Change this to your gmail adress
$mailer->Password = ‘{password}’; // Change this to your gmail password
$mailer->From = ‘{someid}@gmail.com’; // This HAVE TO be your gmail adress
$mailer->FromName = ‘Venkat’; // This is the from name in the email, you can put anything you like here
$mailer->Body = ‘Message body’;
$mailer->Subject = ‘Message subject’;
$mailer->AddAddress(‘{toaddress email id}’); // This is where you put the email adress of the person you want to mail
if(!$mailer->Send())
{
echo “Message was not sent
”;
echo “Mailer Error: ” . $mailer->ErrorInfo;
}
else
{
echo “Message has been sent”;
}
?>

0 comments: