0

Hi
I want to send mails using gmail server with my gmail id and password. I am using the php mailer class for sending mails. Please help me to do this. my code is shown below

<?php
$mail             = new PHPMailer();
$body             = "Test mail Test mail";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 1; 
$mail->SMTPSecure = 'tls';                    // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.gmail.com"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "test@gmail.com"; // SMTP account username
$mail->Password   = "password";        // SMTP account password

$mail->SetFrom('test@gmail.com', 'First Last');

$mail->AddReplyTo("test@gmail.com","First Last");

$mail->Subject    = "Test mail";

$mail->AltBody    = "Test mail"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "myemail@gmail.com@gmail.com";
$mail->AddAddress($address, "Testing");




if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>
2
Contributors
6
Replies
23
Views
3 Years
Discussion Span
Last Post by pritaeas
0

yes.. i am getting the error
MTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.