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!";
}
?>