I am using this php code to send email through gmail account . but its showing smtp error . I have googled it . but not found any specific answer . would anyone please help to find the solution ??
I have hosted this code in my webserver
error : "SMTP Error: Could not connect to SMTP host. Message was not sent Mailer Error: SMTP Error: Could not connect to SMTP host.SMTP Error: Could not connect to SMTP host."
code:
<?php
require("class.phpmailer.php");
$email = $_POST['email_address'];
$username = 'username@gmail.com'; //your gmail address
$password = 'password'; //password
send_mail_to_subscriber();
function send_mail_to_subscriber()
{
global $username,$password,$email;
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = $username;
$mailer->Password = $password;
$mailer->From = $username;
$mailer->FromName = $username;
$mailer->Body = 'this is a message';
$mailer->Subject = 'this is a subject';
$mailer->AddAddress($email);
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Download link has been sent to your email address";
}
}
?>