Problem in using smtp.google.com from phpMailer

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
amika
Forum Newbie
Posts: 1
Joined: Wed Feb 25, 2009 8:55 pm

Problem in using smtp.google.com from phpMailer

Post by amika »

I have downloaded the newest version of phpMailer and try to send email from smtp.google.com. I test it but "Mailer Error: SMTP Error: Could not connect to SMTP host." is shown. Does anyone can help? Here is my code:

Code: Select all

<?php
include("class.phpmailer.php");
include("class.smtp.php");
 
$mail             = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
 
$mail->Username   = "abc@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxx";            // GMAIL password
 
$mail->AddReplyTo("abc@gmail.com","abc");
 
$mail->From       = "abc@gmail.com";
$mail->FromName   = "abc";
 
$mail->Subject    = "PHPMailer Test Subject via gmail";
 
$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap
 
$mail->MsgHTML($body);
 
$mail->AddAddress("abc@hotmail.com", "abc");
$mail->AddAddress("abc@gmail.com", "abc");
$mail->AddAddress("abc@ymail.com", "abc");
 
// $mail->AddAttachment("images/phpmailer.gif");             // attachment
 
$mail->IsHTML(true); // send as HTML
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>
Post Reply