[英]PHP contact form not sending email even after saying email sent
我在我的網站上整理了一個簡單的PHP聯系人表格。 當我提交消息時,它說消息已發送。 但是我沒有收到電子郵件。
我正在使用的代碼如下
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<div class="field half first">
<label for="name">Name</label>
<input name="name" id="name" type="text" placeholder="Name">
</div>
<div class="field half">
<label for="email">Email</label>
<input name="email" id="email" type="email" placeholder="Email">
</div>
<div class="field">
<label for="message">Message</label>
<textarea name="message" id="message" rows="6" placeholder="Message"></textarea>
</div>
<ul class="actions">
<li><input value="Send email" class="button alt" type="submit"></li>
</ul>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("xyz@website.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
MX記錄是為Google應用設置的,這與為什么不發送電子郵件有什么關系嗎?
您的代碼對我來說似乎不錯。
如果在localhost上執行此操作,則可能是因為未正確配置SMTP,所以您發送郵件的地址拒絕了它。
如果是這種情況,請嘗試將其上傳到遠程服務器。 或在計算機上配置SMTP。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.