970_90

Tuesday, 6 September 2011

PHP MAILER setting to send email through Gmail

PHP MAILER setting to send email through Gmail

Step 1:
Download a recent version of PHPMailer.

Step 1:
Use Following code to send an email from Gmail Account.

 
$mail = new PHPMailer(); 
$mail->IsSMTP(); // set mailer to use SMTP 
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server 
$mail->Port = 465; // set the port to use 
$mail->SMTPAuth = true; // turn on SMTP authentication 
$mail->Username = "[email protected]"; // your SMTP username or your gmail username 
$mail->Password = "password"; // your SMTP password or your gmail password 
$from = "[email protected]"; // Reply to this email 
$to="[email protected]"; // Recipients email ID 
$name="Jersey Name"; // Recipient's name 
$mail->From = $from; 
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name); 
$mail->AddReplyTo($from,"Webmaster"); 
$mail->WordWrap = 50; // set word wrap 
$mail->IsHTML(true); // send as HTML 
$mail->Subject = "Sending Email From Php Using Gmail"; 
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body 
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body 
if(!$mail->Send()) { 
 echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
echo "Message has been sent"; 
} 

If you get similar to following Error
Please log in via your web browser and then try again.
5.7.14 Please log in via your web browser and then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 fr13sm3613053pdb.81

If Yes, 
whether you have "turned on 2-Step Verification" OR Google need Verification that you want to use your gmail as SMTP credential.

You can fix this in couple of minutes using below link:
https://support.google.com/mail/answer/78754

If any issue, please comment below in comment box:



No comments:

Post a Comment