Thursday, June 2, 2011

Sending email in PHP from Gmail

Sending email in PHP from Gmail

For sending email in PHP by Gmail id, I have used phpmailer class.
Note that php_openssl must be un-commented in the php.ini file.
In phpMailer directory open "class.phpgmailer.php"  and change the line as listed below:
var $Host        = "ssl://smtp.gmail.com";
var $Port        = 465;


Put listed below code in php file from where you want to send email.
require_once('phpgmailer/class.phpgmailer.php');
$mailToClient=new PHPGMailer();
$mailToClient->IsHTML(true);
$mailToClient->Username='full-gmail-address';//'a@gmail.com';  
$mailToClient->Password='gmail-password-here';//amitabc123  
$mailToClient->From='full-gmail-address';//a@gmail.com';  
$mailToClient->FromName='Amit';
$mailToClient->Subject='YOUR-SUBJECT';//a@gmail.com
$mailToClient->AddAddress('recipient email address here');
$mailToClient->Body='Hey, Here is Amit!';
$mailToClient->Send();

No comments:

Post a Comment