php mail false,php mail()返回false

我想在有人提交聯繫表單時從服務器發送電子郵件。這裏是示例php代碼。php mail()返回false

if($_SERVER['REQUEST_METHOD'] == "POST"){

$name = strip_tags(trim($_POST['name']));

$email = strip_tags(trim($_POST['email']));

$dept = strip_tags(trim($_POST['dept']));

$message = strip_tags(trim($_POST['message']));

if((!isset($email) || empty($email)) || (!isset($name) || empty($name)) || (!isset($dept) || empty($dept)) || (!isset($message) || empty($message))){

echo -1;

return;

}

if(filter_var($email, FILTER_VALIDATE_EMAIL)===false){

echo -2;

return;

}

$to = '[email protected]';

$email_subject = "Splendenti Eye Wear | Contact Us";

$email_body = "Contacted by\nName: $name\nEmail: $email\nDepartment: $dept\nMessage: $message";

$headers = "[email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]

$headers .= "Reply-To: ".$_POST['email'];

if(mail($to,$email_subject,$email_body,$headers)){

echo 1; // email sent

}

else{

echo "failed to send email";

}

}else{

echo "Invalid Request";

}

?>

但郵件函數返回false。任何人都可以指導?

+0

是您的電子郵件服務器配置(sendmail/smtp) –

+0

我該如何檢查@SureshKamrushi? –

+0

[閱讀文檔](http://php.net/manual/en/function.mail.php)和用戶評論。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值