Sending mail using phpMailer via Gmail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Sending mail using phpMailer via Gmail

Post by anjanesh »

Anyone know how to send a mail using phpMailer via Gmail ?

Code: Select all

include_once("class.phpmailer.php");
    
$body  = "test";    
$text_body  = "test";

$mail = new PHPMailer();

$mail->Username = "username@gmail.com";
$mail->Password = "password";
$mail->From     = "username@gmail.com";
$mail->FromName = "Someone";
$mail->Host     = "smtp.gmail.com:587";
$mail->Mailer   = "smtp";
$mail->Body     = $body;
$mail->AltBody  = $text_body;

$mail->AddAddress("someone@somedomain.com", "Someone Else");
$mail->IsSMTP();

if (!$mail->Send())
 echo 'Failed : '.$mail->ErrorInfo;
Running this on my PC returns Failed : The following From address failed: username@gmail.com.

Thanks
Post Reply