电子邮件不会从localhost examplep 3.2.1发送


E-mails do not send out from localhost xampp 3.2.1

我在从localhost(XAMPP 3.2.1)发送电子邮件时遇到问题。我想使用Gmail收件箱发送电子邮件。

在我的情况下,我做了与本教程中类似的一切:http://www.websnippetz.com/php/send-email-from-xampp-localhost/

sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourname@gmail.com
auth_password=gmailpassword
force_sender=yourname@gmail.com

php.ini

[mail function]
SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = yourname@gmail.com
sendmail_path = "'"D:'xampp'sendmail'sendmail.exe'"-t"
mail.add_x_header = Off 

然后重新启动服务器。

我发送电子邮件的代码:

<?php
 $to = "tome@example.com";
 $subject = "Hi!";
 $body = "Hi,'n'nHow are you?";
 if (mail($to, $subject, $body)) {
   echo("<p>Email successfully sent!</p>");
  } else {
   echo("<p>Email delivery failed…</p>");
  }
 ?>

运行代码后,我的邮箱里什么都没有。。。请寻求帮助。

试试这个,

php.ini文件中:

[mail function]
SMTP = localhost
smtp_port = 25
;sendmail_from = yourname@gmail.com
;sendmail_path = "'"D:'xampp'sendmail'sendmail.exe'"-t"
mail.add_x_header = Off

并在php代码中设置from地址,例如:

$from = "john@example.com";

此外,我认为您不需要更改sendmail.ini文件中的任何设置。

希望这能有所帮助。

此外,您还可以使用phpmailer类来发送邮件。