简体   繁体   中英

PHPMailer() + IIS + SMTP = SMTP Error: Could not connect to SMTP host

I have truble with sending E-mail through my PHP site. I use code below (tried everything I could google, but this makes to me the most sense - still it does not work)

$mail = new PHPMailer();
$mail->From = "me@localhost";
$mail->FromName = "My Name";
$mail->AddAddress("someExistingAddress@gmail.com");
$mail->Subject = "Test PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->Subject    = "PHPMailer Test Subject via smtp";
$mail->Host = "localhost"; // SMTP server
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = false;
$mail->Port = 25;
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Execution causes: “SMTP Error: Could not connect to SMTP host”.

I installed SMTP on my IIS (7.5) on Windows 7 and here are my settings (translated from Polish):

SMTP:
Address e-mail:
me@localhost (what is that field? It even does not check correctness, I can type in sth without @)
Send e-mail to server SMTP:
localhost
Port:
25
And no-authentication required.

Php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

php_openssl.dll ENABLED

Please give me some direct guidelines, as I wasted too much time on countless trials with no success.

而不是本地主机尝试 127.0.0.1

Your php mailer file is correct but you have to use the current host. You can get a free SMTP account on sendgrid for testing you can use this SMTP account.

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