【问题标题】:Contact form sends email but has no message联系表格发送电子邮件但没有消息
【发布时间】: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


【解决方案1】:

验证您的表单是否具有正确的“名称”属性。 你的代码很脏。

【讨论】:

  • 一切都是正确的。我测试了 html 和 php,它工作得非常好,但是当我将它与其他所有内容一起添加到我的网站时,电子邮件是空的。
  • 这真的很奇怪,你能在发送电子邮件之前做一个 vardump 吗
  • 我尝试在 vardump 中添加,然后表单不会发送。我注意到我是否做对了。值得一提的是我的网站来自引导模板吗?
  • @JaneDoe 你真的测试过吗?两件事... 1. userSubject 没有表单输入(作为通知警告出现...) 2. 请注意您为 $headers 所做的事情,而您没有为 $body_message 做的事情!这将产生另一个通知。
  • @TimBrownlaw 是的,我做到了。所以我必须使用 $headers.drive.google.com/a/benilde.edu.ph/file/d/… 它工作得很好。
猜你喜欢
  • 2018-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-07
相关资源
最近更新 更多