I have been searched many hours to solve my problem and i failed.
This is my simple code use PHPMailer to send email with Gmail
in xampp and get this error each time:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
and this is my php code :
<?php
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->HOST = 'smtp.gmail.com';
$mail->PORT = '465';
$mail->isHTML();
$mail->Username = '##myemail##@gmail.com';
$mail->Password = '##mypass##';
$mail->SetFrom('no-reply@howcode.org');
$mail->Subject = 'Hello World';
$mail->Body = 'A test email!';
$mail->AddAddress('hamidreza.mohammadian@yahoo.com');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
please help me.