php 邮件功能在本地主机服务器中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14802606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:00:04  来源:igfitidea点击:

mail function is not working in localhost server

phpemaillocalhost

提问by user1995927

I am on my localhost server. I am using this code below, but I never received the email.

我在我的本地主机服务器上。我在下面使用此代码,但我从未收到电子邮件。

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

回答by shona

I know its kinda late...

我知道有点晚了...

check if your localhost is configured to send email

检查您的本地主机是否配置为发送电子邮件

On ubuntu terminal try executing following command

在 ubuntu 终端上尝试执行以下命令

# apt-get install sendmail

回答by Johannes Mittendorfer

Make sure that the mailserver is configured correctly in the php.ini file.

确保在 php.ini 文件中正确配置了邮件服务器。

comment out these lines like this in php.ini file and restart the Apache server.

在 php.ini 文件中像这样注释掉这些行并重新启动 Apache 服务器。

/*[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = localhost
; smtp_port = 25
*/

/*; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost
*/