邮件功能在 PHP 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20297703/
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
Mail function is not working in PHP
提问by PHPCoder
<?php
if (isset($_POST['submit']))
{
//if "email" is filled out, proceed
$name= mysql_real_escape_string($_POST['name']);
$phone= mysql_real_escape_string($_POST['phone']);
$to = "[email protected]";
$subject = "Customer Intrested";
$message = "Buyer Information and Intrested in land.";
$message.= "Customer Name :".$name."\n";
$message.= "Customer Phone :".$phone."\n";
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "success";
} else {
echo "failed.";
}
?>
I am using the above code to send email..but i am unable to get the result..it always showing the "Thank you message"..
我正在使用上面的代码发送电子邮件..但我无法得到结果..它总是显示“谢谢消息”..
I can able to get the values of name and phone.
我可以获取 name 和 phone 的值。
How to fix this Problem?
如何解决这个问题?
回答by Bhadra
mail($to, "Subject: $subject",$message );
echo "Thank you for using our mail form";
instead of this ,first check if the mail is sent
而不是这个,首先检查邮件是否已发送
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
By this actually u can know whether your mail function in working or not
通过这个实际上你可以知道你的邮件功能是否在工作
if it is not working.the problem can be with SMTP settings in your localhost
如果它不起作用。问题可能出在本地主机中的 SMTP 设置上
enable errors in php if not enabled using
如果未启用,则启用 php 中的错误
ini_set('display_errors',1);
回答by Aman Maurya
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
for more help:http://www.w3schools.com/php/php_mail.asp

