PHP Mailer Fails To Connect To Server

情到浓时终转凉″ 提交于 2019-12-13 05:24:09

问题


here is my php code:

require_once('class.phpmailer.php');

$mail = new PHPMailer(); 
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'clubbedinapp@gmail.com';
$mail->Password = 'pw';
$mail->SMTPAuth = true;

$mail->From = 'clubbedinapp@gmail.com';
$mail->FromName = 'Clubbed In';
$mail->AddAddress('nishil.shah17@gmail.com');
$mail->AddReplyTo('clubbedinapp@gmail.com', 'Information');

$mail->IsHTML(true);
$mail->Subject    = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
$mail->Body    = "Hello";

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Message sent!";
}

I followed a Gmail PHPMailer tutorial, I have no idea what is wrong? Can someone please help?


回答1:


Did you enable openssl on your php.ini?

Go to PHP.ini and find a line called

;extension=php_openssl.dll

and remove the semi colon in the beginning of the line.

Stop the Apache server and all servers, start them again, and try it again.



来源:https://stackoverflow.com/questions/18290233/php-mailer-fails-to-connect-to-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!