使用PHP在XAMPP中从localhost发送邮件


Sending mails from localhost in XAMPP with PHP

我在Stack Overflow上看到了很多问题和答案,并尝试了其中许多问题和答案在XAMPP中从localhost发送邮件,但所有的尝试都是徒劳的。这是我的semdmail.ini文件:

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=******@gmail.com
auth_password=***
force_sender= *****@gmail.com

我的php.ini文件包含这个

sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"
mail.add_x_header = Off

我的php文件如下

<?php
if(mail ('abcd@gmail.com', 'asdf', 'asdf', 'From: vh@gmail.com'))
{
    echo 'success';
}else
{
    echo 'sorry';
}
?>

虽然我在网上看到了,但我还是找不到一个有效的解决方案。

尝试:

  • 在php.ini(C:''examplep''php''php.ini)中取消注释"extension=php_openssl.dll"
  • 在php.ini中取消注释并配置"[mail function]"部分:

_

[mail function]
SMTP = smtp.gmail.com  
SMTP = smtp.gmail.com
smtp_port = 587
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:'program filesC:'xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:'sendmail) and use this for sendmail_path.  
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:'xampp'mailoutput folder
sendmail_path="C:'xampp'mailtodisk'mailtodisk.exe"

希望它能帮助