为什么我的 php 表单仅适用于某些电子邮件而不适用于所有联系人提交?

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

我在他们的网站上使用了客户的联系表格电子邮件,因为我的标准电子邮件在她的网站上不起作用。现在,她收到了一些表单提交,例如我的和随机的,但是当我使用我的个人电子邮件或她的个人电子邮件提交时,她根本没有收到联系表单电子邮件。

这段代码没有发送有什么问题吗?很高兴提供您需要的任何附加代码(例如表格)。

PHP 脚本 (mail.php)

function stripFormSlashes($arr)
    {
        if(!is_array($arr))
        {
            return stripslashes($arr);
        }
        else
        {
            return array_map('stripFormSlashes', $arr);
        }
     }
 
     if(get_magic_quotes_gpc())
     {
        $_POST = stripFormSlashes($_POST);
     }
  $message = "";
  $message .= "First Name: " . htmlspecialchars($_POST['first_name'], ENT_QUOTES) . "<br \>\n";
  $message .= "Last Name: " . htmlspecialchars($_POST['last_name'], ENT_QUOTES) . "<br \>\n";
  $message .= "Email: " . htmlspecialchars($_POST['email'], ENT_QUOTES) . "<br \>\n";
  $message .= "Phone: " . htmlspecialchars($_POST['telephone'], ENT_QUOTES) . "<br \>\n";
  $message .= "Company: " . htmlspecialchars($_POST['company'], ENT_QUOTES) . "<br \>\n";
  $message .= "Comments: " . htmlspecialchars($_POST['message'], ENT_QUOTES) . "<br \>\n";
  $lowmsg = strtolower($message);
  $injection_strings = array ( "content-type:","charset=","mime-version:","multipart/mixed","bcc:","cc:");
  foreach($injection_strings as $suspect)
  {
   if((stristr($lowmsg, $suspect)) || (stristr(strtolower($_POST['first_name']), $suspect)) || (stristr(strtolower($_POST['email']), $suspect)))
   {
     die ( 'Illegal Input.  Go back and try again.  Your message has not been sent.' );
   }
  }
 $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n";
 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
 $headers .= "From: \"" . $_POST['first_name'] . " " . $_POST['last_name'] . "\" <" . $_POST['email'] . ">\r\n";
 $headers .= "Reply-To: " . $_POST['email'] . "\r\n";
  mail("[email protected]", "Contact Form Submission", $message, $headers);
  header("Location: ../thank_you.html");
?>

表单模态

<div
            class="modal fade"
            id="contactForm"
            data-bs-backdrop="static"
            data-bs-keyboard="false"
            tabindex="-1"
            aria-labelledby="contactFormLabel"
            aria-hidden="true"
        >
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div
                        class="modal-header border-0"
                        style="background-color: var(--tp-theme-main-bg)"
                    >
                        <h2
                            class="modal-title fs-5"
                            id="ContactFormLabel"
                            style="font-size: 36px !important"
                        >
                            Contact Me!
                        </h2>
                        <button
                            type="button"
                            class="btn-close"
                            data-bs-dismiss="modal"
                            aria-label="Close"
                        ></button>
                    </div>
                    <div class="modal-body form-group col-12 px-5">
                        <p>
                            contact text
                        </p>
                        <form
                            action="./assets/mail.php"
                            method="POST"
                            id="contactForm"
                        >
                            <div class="row g-3">
                                <div class="col-md-6">
                                    <div class="input-item">
                                        <input
                                            type="text"
                                            name="first_name"
                                            placeholder="First Name"
                                            required
                                        />
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="input-item">
                                        <input
                                            type="text"
                                            name="last_name"
                                            placeholder="Last Name"
                                            required
                                        />
                                    </div>
                                </div>
                                <div class="col-lg-12">
                                    <div class="input-item">
                                        <input
                                            type="text"
                                            name="company"
                                            placeholder="Company Name"
                                        />
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="input-item">
                                        <input
                                            type="text"
                                            name="email"
                                            placeholder="Email Address"
                                            required
                                        />
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="input-item">
                                        <input
                                            type="tel"
                                            name="telephone"
                                            placeholder="(555) 123-4567"
                                        />
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="input-item-textarea">
                                        <textarea
                                            name="message"
                                            placeholder="Let us know what you're looking for"
                                            required
                                        ></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer border-0 me-auto flex-row-reverse flex-md-row">
                                <button
                                    type="button"
                                    class="btn btn-secondary"
                                    data-bs-dismiss="modal"
                                >
                                    Close
                                </button>
                                <button
                                    type="submit"
                                    name="submit"
                                    class="btn btn-primary"
                                    style="position: relative"
                                >
                                    Submit
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

我尝试稍微更改一下 FROM,看看这是否会导致问题,但这似乎完全杀死了提交。

php forms
1个回答
0
投票

启用错误日志以检查电子邮件失败的原因。您可以通过在文件顶部添加行来启用

error_reporting(E_ALL);
ini_set('display_errors', 1);

并且您还尝试更改您的注入字符串代码,如下所示

$injection_strings = array(
    "content-type:", "mime-version:", "boundary=", "bcc:", "cc:", "to:", "from:", "reply-to:"
);
foreach ($injection_strings as $suspect) {
    if (preg_match("/" . preg_quote($suspect, '/') . "/i", $lowmsg) ||
        preg_match("/" . preg_quote($suspect, '/') . "/i", strtolower($_POST['first_name'])) ||
        preg_match("/" . preg_quote($suspect, '/') . "/i", strtolower($_POST['email']))) {
        die('Illegal Input.  Go back and try again.  Your message has not been sent.');
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.