PHP邮件功能正在发送空白邮件正文

问题描述 投票:0回答:1

我知道还有其他类似的问题,但是他们的回答并不能解决我的问题。

我开发了一个网站,并暂时决定继续使用PHP邮件,而不是其他途径,因为它是最快,最简单的方式(我是一名业余开发人员)。在过去的一个月中,它运行良好,没有任何问题,但是三天前,我开始收到没有邮件内容的电子邮件(这些邮件不是垃圾邮件,或者只是空邮件,我知道我应该使用验证等)。

我仍然成功地收到了发送到我的电子邮件帐户的电子邮件,其中还包含主题标题为“ Contact Form Request”,但是正文为空,即不是应该填充的$ msg吗?

我切换了“联系表单请求”和$ msg的位置,并且$ msg内容将在电子邮件主题标头中接收,因此将其填充,但是消息正文保持为空。

任何帮助将不胜感激。

contact.html

<div id="contact-form">
        <form action="contact.php" method="post">

          <div class="form-group">
            <label for="inputName">Name *</label>
            <input type="text" class="form-control" name="name" placeholder="Enter name" required>
          </div>

          <div class="form-group">
            <label for="inputNumber">Contact Number *</label>
            <input type="tel" class="form-control" name="phone" placeholder="Enter contact number" required inputMode="tel">
          </div>

          <div class="form-group">
            <label for="inputEmail">Email *</label>
            <input type="email" class="form-control" name="email" placeholder="Enter email" required>
          </div>

          <div class="form-group">
            <label for="inputSubject">Subject *</label>
            <input type="text" class="form-control" name="subject" placeholder="Enter subject" required>
          </div>

          <div class="form-group">
            <label for="inputMessage">Message *</label>
            <textarea type="text" class="form-control" name="message" placeholder="Enter message" rows="3" required maxlength="300"></textarea>
          </div>

          <p><small><strong>*</strong> These fields are required.</small></p>

          <button type="submit" class="btn btn-send">Send</button>

        </form>
      </div>

contact.php

<?php

$webmaster_email = "[email protected]";

$success_page = "thankyoucontact.html";

$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];

$msg =
"You have received a message from " . $name . "\r\n\n" .
"Subject: " . $subject . "\r\n\n" .
"Message: " . $message . "\r\n\n" .
"Name: " . $name . "\r\n" .
"Phone: " . $phone . "\r\n" .
"Email: " . $email . "\r\n\n\n\n" .
"DISCLAIMER:\r\n\nThis e-mail and any attachments is a confidential correspondence intended only for use of the individual or entity named above. If you are not the intended recipient or the agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender by phone or by replying this message, and then delete this message from your system.";

mail($webmaster_email, "Contact Form Request", $msg);
header("Location: $success_page");

?>
php email
1个回答
0
投票

您的代码在第一次检查时看起来不错(不是安全的,但可以正常工作。)>

我的建议:

第一:调试。仅显示消息而不是实际邮件。如下所示:

<?php

$webmaster_email = "[email protected]";

$success_page = "thankyoucontact.html";

$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];

$msg =
"You have received a message from " . $name . "\r\n\n" .
"Subject: " . $subject . "\r\n\n" .
"Message: " . $message . "\r\n\n" .
"Name: " . $name . "\r\n" .
"Phone: " . $phone . "\r\n" .
"Email: " . $email . "\r\n\n\n\n" .
"DISCLAIMER:\r\n\nThis e-mail and any attachments is a confidential correspondence intended only for use of the individual or entity named above. If you are not the intended recipient or the agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender by phone or by replying this message, and then delete this message from your system.";

echo "The message contains: $msg";    
exit;

// mail($webmaster_email, "Contact Form Request", $msg);
// header("Location: $success_page");
?>

如果您的消息包含您期望的内容,则必须调查电子邮件网关。这要困难得多。

我将从制作这样的脚本开始,仅在其中包含它的名称将其称为testmail.php,然后看看是否可行。

<?php
mail('[email protected]', "testing", "testing.\nDoes this arrive?");
?>

编辑:第三件事要检查:

您正在发送纯文本邮件。也许您的电子邮件客户端仅显示HTML电子邮件?请检查。

© www.soinside.com 2019 - 2024. All rights reserved.