mail function is not working in localhost server

。_饼干妹妹 提交于 2019-12-01 18:10:03

问题


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

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

回答1:


I know its kinda late...

check if your localhost is configured to send email

On ubuntu terminal try executing following command

# apt-get install sendmail



回答2:


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

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

/*[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
*/


来源:https://stackoverflow.com/questions/14802606/mail-function-is-not-working-in-localhost-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!