Kaw*_*iKx 0 html php forms email
我正在建立一个网站作为练习.它有一个"联系我们"页面,我在其中创建了一个表单.我已经用.php扩展名保存了该页面,相信在这种情况下,网页会将表单数据发送到另一个php页面.一旦按下发送按钮,它将导致带有html和php脚本的php页面,该脚本应自动发送电子邮件.但那并没有发生.这是PHP脚本:
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$country = $_POST['country'];
$city = $_POST['city'];
$message = $_POST['contactusmessage'];
$headers = 'xxx@xxx.com';
$to = 'xxx@xxx.com';
$mail=mail($to,$message,$headers);
if($mail){
echo"<p>Thanks $name for the message.</p>";
echo"<p>We will reply to $email</p>";
}
else{
echo "Mail sending failed.";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
请告诉我哪里出错了?
$headers = 'admin@bulkbuying.biz';
我突然看到这是一个无效的标题.这可能就是为什么你的邮件没有出去的原因.尝试将其更改为$headers = 'From: admin@bulkbuying.biz';
也改变你$mail=mail($to,$message,$headers);
到$mail=mail($to,'This is the subject',$message,$headers);
如下面的其他答复中提到.你错过了主题参数mail()
.