【发布时间】:2015-07-02 11:14:37
【问题描述】:
我把这段代码放在同一页的顶部:
<?php
if(isset($_POST['submit'])){
$to = "rightysahu@gmail.com";
$from = $_POST['email'];
$first_name = $_POST['first_name'];
$message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
这里是html(同一页面)编码:
<form action="" method="post" >
<input type="text" name="first_name" placeholder="Name" />
<input type="text" name="email" placeholder="Email" />
<textarea name="message" placeholder="Message"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
表单提交成功,但没有收到电子邮件(收件箱)。请找出错误。(在我的网站上而不是在本地服务器上运行。)
【问题讨论】:
-
如果你在 Localhost 上运行,你需要设置本地发送电子邮件
-
使用
if( mail($to,$subject,$message,$headers)){echo "mail sent";}else{echo "not sent;"}
标签: php email contact-form