简体   繁体   中英

Windows Apache2.2 PHP5 PHPMailer Error

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?

Solution from the original poster:

Just change

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM