【发布时间】:2018-05-16 21:37:10
【问题描述】:
我的网站 PHP 代码有问题。正在发送电子邮件,但没有消息。
This is the email I get when it sends. It's empty.
Data I input in my contact form
我在没有 css 文件和引导程序的情况下测试了我的 php 代码,并完美地收到了带有消息的电子邮件。但是,当我包含所有内容(从 CSS 和引导代码)时,我收到的电子邮件没有任何消息。
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 = 'info@mariamulan.com'; /* 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
hello.mariamulan@gmail.com instead.');
window.location = 'index.html'; /* Where you want to get directed
*/
</script>
<?php
}
?>
【问题讨论】:
-
检查
$_POST是否有数据或全部为空白 -
在电子邮件中,一切都是空白的。
-
在邮件中,一切都是空白的,bcz
$_POST变量是空白的。 -
我可能把你弄糊涂了,我放了数据进行测试,但是当我检查电子邮件时,它是空的,并且包含了所有其他的 css。
-
messafe是什么?
标签: php email send contact-form