Thursday, 8 September 2011

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';//'pxyz@gmail.com';
$mailToClient->Password='gmail-password-here';//abc123
$mailToClient->From='full-gmail-address';//pxyz@gmail.com';
$mailToClient->FromName='Parvez';
$mailToClient->Subject='YOUR-SUBJECT';//sending mail
$mailToClient->AddAddress('recipient email address here');
$mailToClient->Body='Hey, Here is Parvez!';
$mailToClient->Send();

No comments:

Post a Comment