Windows Apache2.2 PHP5 PHPMailer Error

邮差的信 提交于 2019-12-13 04:20:44

问题


I have been reading some older questions and I haven't found yet the solution to my problem. Here it goes.

I'm developing a cool website with some mail functions, limited for admin users. Right now I'm developing the site on localhost, but I've been provided with a Gmail account that will be used for the website.

I've been seeking through the web and the PHPMailer module seems a good election.

My idea is to send emails from my localhost to any other email address using the Gmail account.

Here are the codes I'm using. For the Apache2.2 server

LoadModule ssl_module modules/mod_ssl.so

For php.ini

[mail function]
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from = admins.domaing@gmail.com

And the php codes

<?php
  date_default_timezone_set("Europe/Madrid");   
  require_once("class.phpmailer.php"); 
  $mail = new PHPMailer();
  $body             = 'It works!';
  $mail->IsSMTP();
  $mail->Host       = "smtp.gmail.com";
  $mail->SMTPDebug  = 2; 
  $mail->SMTPAuth   = true;
  $mail->SMTPSecure = "ssl";
  $mail->Host       = "smtp.gmail.com";
  $mail->Port       = 465; 
  $mail->Username   = "admins.domaing@gmail.com";
  $mail->Password   = "*********";
  $mail->SetFrom('admins.domaing@gmail.com', 'Admin');
  $mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic"; 
  $mail->MsgHTML($body);
  $address = "user@email.com";
  $mail->AddAddress($address, "user name");
  if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
  } else {
    echo "Message sent!";
  }
?>

Actually the error I'm getting is:

Invalid XML: SMTP -> ERROR: Failed to connect to server: (0)

Any suggestions?


回答1:


Solution from the original poster:

Just change

$mail->Username = "admins.domaing@gmail.com";

to

$mail->Username = "admins.domaing";



来源:https://stackoverflow.com/questions/15521940/windows-apache2-2-php5-phpmailer-error

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