实际上,我在使用sendmail方面还是新手,但是我已经读了很多关于这方面的文章,并且只是重定向我使用PHPmailer、迅捷邮件等等.但如果不了解基本知识,就很难理解。所以我决定尝试简单,这就是我所拥有的。
我已经配置了我的php.ini:
[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On我的sendmail.ini:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=mygmail@gmail.com
auth_password=mypassword
hostname=localhost我有这个PHP代码:
$to = 'mygmail@gmail.com';
$message = $_POST['message'];
$email = $_POST['email'];
$contact_num = $_POST['contact_number'];
$headers = 'From:'.'$email' . "\r\n" .'$contact' . "\r\n" .
'Reply-To: mygmail@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $message, $headers);但是,当我单击submit按钮时,sendmail.exe就会出现,什么也不会发生。当我检查error.log时,上面写着:
14/07/01 23:23:48 : Connection Closed Gracefully.发布于 2014-09-02 19:42:06
这个部分是post: Sendmail Wamp Php的副本和粘贴
问题是sendmail必须作为管理员运行。这是帮助任何一个人解决我的问题的办法。
如果这还不起作用(我的答案)
确保服务器(或IDE)以admin的身份运行,方法之一是:
1)右键单击程序(例如,服务器、ide、命令提示符),然后单击“以管理方式运行”。
2)或右键单击“program> properties> compatiblity>”执行管理。
例如,如果您在构建的服务器中使用PHP,请以admin方式运行命令提示符,然后使用
C:\wamp\bin\php\php5.5.12\php.exe -S localhost:80 -t C:\Users\path\to\rootFolder当然,更改文件路径以满足您的需要。
编辑:这很可能是您进入https://bugs.php.net/bug.php?id=44994的错误
发布于 2016-01-14 06:47:12
解决方案是设置sendmail.ini和php.ini
您需要与您的isp通信,以了解什么是开放的smtp服务器,他们大多数都有一个,这是类似于smtp.yourisp.com的大多数时间。
您还可以使用自己的电子邮件服务器或现有的电子邮件地址来设置smtp --这将需要额外的设置,例如特定的smtp服务器、端口号、迫使sendmail成为实际邮件、用户名、密码和大多数情况下的ssl。
php.ini
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP = smtp.yourisp.mu smtp_port = 25
; For Win32 only. ; http://php.net/sendmail-from sendmail_from = postmaster@yourisp.com
; 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"确保php和sendmail作为管理员运行似乎是个好主意,但这并没有解决我的问题。
sendmail.ini中的解决方案
smtp_server = smtp.yourisp.com
; smtp port (normally 25)
smtp_port=25
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=none不要使用导致我的错误的smtp_ssl = auto,只需根据您服务器的规范将其设置为ssl或none
发布于 2017-02-02 23:28:57
确保以管理员身份运行XAMPP。通过右键单击它并单击“以管理员身份运行”,就可以做到这一点。帮我修好了。
https://stackoverflow.com/questions/24514432
复制相似问题