联系表格发送电子邮件,但没有消息
我遇到了我的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
}
?>
回答:
确认您的形式有正确的 “名称” 属性。 你的代码很肮脏寿。
以上是 联系表格发送电子邮件,但没有消息 的全部内容, 来源链接: utcz.com/qa/259838.html