Monday, February 22, 2010

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

Download the phpmailer classes At

Then use the below code to send emails.
$mailer = new PHPMailer();
$mailer->Host = ’ssl://′;
$mailer->SMTPAuth = TRUE;
$mailer->Username = ‘{somename}’; // Change this to your gmail adress
$mailer->Password = ‘{password}’; // Change this to your gmail password
$mailer->From = ‘{someid}’; // 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
echo “Message was not sent
echo “Mailer Error: ” . $mailer->ErrorInfo;
echo “Message has been sent”;