<?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 = "admin@gmail.com";
$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.";
}
?>
我使用上面的代码发送电子邮件..但我无法得到结果..总是显示“谢谢你的消息”..
我可以获取姓名和电话的价值。
如何解决此问题?
答案 0 :(得分:12)
mail($to, "Subject: $subject",$message );
echo "Thank you for using our mail form";
而不是这个,首先检查邮件是否已发送
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
实际上你可以知道你的邮件是否正常工作
如果它不起作用。问题可能出在localhost中的SMTP设置
如果未使用
启用,则启用php中的错误ini_set('display_errors',1);
答案 1 :(得分:2)
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);