联系表格发送电子邮件,但没有消息
我遇到了我的PHP代码为我的网站出现问题。电子邮件正在发送,但没有消息。联系表格发送电子邮件,但没有消息
This is the email I get when it sends. It's empty.
Data I input in my contact form
我测试我的PHP代码,而无需在css文件和引导,并与收到的消息的电子邮件完美。但是当我把所有的东西都包含进去,从css和bootstrap代码,我收到没有任何消息的电子邮件。
HTML代码:
<div class="contact-form bottom">
<h2> We want to hear from you . Send us a message!</h2>
<form id="main-contact-form" name="contact-form" method="post" action="send_email_test.php">
<div class="form-group">
<input type="text" name="userName" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group">
<input type="email" name="userEmail" class="form-control" required="required" placeholder="Email Id">
</div>
<div class="form-group">
<textarea name="userMessage" id="message" required class="form-control" rows="8" placeholder="Your text here"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-submit" value="Submit">
</div>
</form>
</div>
这是我的PHP代码:
<?php
$field_name = $_POST['userName'];
$field_email = $_POST['userEmail'];
$field_subject = $_POST['userSubject'];
$field_message = $_POST['userMessage'];
$mail_to = '[email protected]'; /* Add your email address here */
$subject = 'Message from website'.$field_name; /* Create your own subject */
$body_message .= 'From: '.$field_name."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\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('Hey! Thanks for the message! We will try to reply to you as soon as possible!');
window.location = 'index.html'; /* Where you want to get directed */
</script>
<?php
} else { ?>
<script language="javascript" type="text/javascript">
alert('Sorry, your message was not sent! Please send an email to
[email protected] instead.');
window.location = 'index.html'; /* Where you want to get directed
*/
</script>
<?php
}
?>
确认您的形式有正确的 “名称” 属性。 你的代码很肮脏寿。
一切都正确无误。我测试了html和php,它工作得很好,但是当我用其他所有东西将它添加到我的网站时,电子邮件是空的。 –
这真的很奇怪,你可以在发送电子邮件之前做一个vardump结果 –
我试着在vardump中添加,然后表单不会发送。我很确定我是否做得对。值得一提的是,我的网站来自bootstrap模板? –
检查'$ _POST'是否有任何数据或一切为空 –
在电子邮件中,一切都是空白的。 –
在电子邮件中,一切都是空白的,bcz'$ _POST'变量为空。 –