对于任何新手错误,我提前道歉,因为这是我第一次真正尝试拼凑 HTML / PhP 联系表格。我已经用相同的问题搜索了以前的问题,但没有发现任何实质内容。
问题是电子邮件没有发送。到目前为止我尝试过的事情: - 确认 SMTP 功能 - 确认这不是与主机相关的问题 - 在另一个模板上使用了这个确切的表单/PHP 邮件,它工作正常 - 检查垃圾邮件文件夹
这是联系表格本身:
<form action="contact.php" method="POST" id="contact-form" class="form">
<input type="hidden" value="" name="check">
<noscript>
<p class="noscript">JavaScript is required to use this form, please make sure your browser supports it.</p>
</noscript>
<p class="input">
<label for="name" class="label">Name</label>
<input type="text" name="name" id="name">
</p>
<p class="input">
<label for="company" class="label">Company</label>
<input type="text" name="company" id="company">
</p>
<p class="input">
<label for="email" class="label">Email</label>
<input type="text" name="email" id="email">
</p>
<p class="input">
<label for="phone" class="label">Phone</label>
<input type="text" name="phone" id="phone">
</p>
<p class="dark input">
<label for="title" class="label">Project Title</label>
<input type="text" name="title" id="title">
</p>
<p class="dark input">
<label for="timeline" class="label">Timeline</label>
<input type="text" name="timeline" id="timeline">
</p>
<p class="dark textarea">
<label for="details" class="label">Details</label>
<textarea name="details" id="details"></textarea>
</p>
<p>
<label for="send" class="send-label">Everything look good? Click send.</label>
<input type="submit" value="Submit" name="submit" class="button">
</p>
</form>
这是 PHP 邮件程序:
<?php
$field_name = $_POST['name'];
$field_company = $_POST['company'];
$field_email = $_POST['email'];
$field_phone = $_POST['phone'];
$field_title = $_POST['title'];
$field_timeline = $_POST['timeline'];
$field_message = $_POST['details'];
$mail_to = 'MyEmail@email.com';
$subject = 'Quote request from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please contact the webmaster.');
window.location = 'contact.html';
</script>
<?php
}
?>
仅供参考,“MyEmail@email.com”不是我使用的电子邮件。出于隐私目的,我使用了替代品。
谢谢!