简体   繁体   English

PHP电子邮件表单未发送电子邮件

[英]PHP email form not sending email

Can anyone help me figure out why this email form won't send an email? 谁能帮助我找出为什么此电子邮件表格不发送电子邮件? I've checked with IT and they said that the email function the server it's on is turned on and other websites being hosted can send emails. 我已经与IT部门核实过,他们说其所在服务器的电子邮件功能已打开,托管的其他网站也可以发送电子邮件。 The form is pulling the data... it just won't send the email. 表单正在提取数据...它只是不会发送电子邮件。 I feel like it's going to be something really obvious that's causing the email to not send and I just can't see it. 我觉得这将是非常明显的事情,导致电子邮件无法发送,我只是看不到它。

<?php 
    require 'topInclude.php';
?>
<div id="contentwrapper">
<div id="waiverContent">
    <div id="dvdContentRight">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            var defaultMessage = "Please provide a brief description of how you plan to adapt the messaging and/or graphic design.";
            $("#myTextArea").focus(function(){
                if( $(this).val() == defaultMessage){
                    $(this).val("");
                }
            }).blur(function(){
                if( $(this).val() == "" ){
                    $(this).val(defaultMessage);
                }
            }).val(defaultMessage);
        });
    </script>

<?php       
if (isset($_POST['submit'])) {

$errors = array(); // Initialize the errors array

if (empty($_POST['company_name'])) {
     $errors[] = 'Please enter your first name.';
} else {
      $Cn = filter_var($_POST['company_name'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}

if (empty($_POST['contact_name'])) {
    $errors[] = 'Please enter your name.';
} else {
    $ln = filter_var($_POST['contact_name'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}

if (empty($_POST['address'])) {
    $errors[] = 'Please enter your work address.';
} else {
    $add = filter_var($_POST['address'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}

if (empty($_POST['email'])) {
    $errors[] = 'Please enter your email address.';
} else {
    $e = filter_var($_POST['email'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}

if (empty($_POST['comments']) || ($_POST['comments'] == 'Please provide a brief description of how you plan to adapt the messaging and/or graphic design.')) {
    $errors[] = 'Please provide a brief description of how you plan to adapt the messaging and/or graphic design.';
} else {
    $co = filter_var($_POST['comments'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}

if (!empty($_POST['phone'])) {
    $p = $_POST['phone'];
} else {
    $p = '';
}

if (empty($_POST['checkbox'])) {
    $errors[] = 'You must agree to the Permission To Use / Reproduce conditions.';
} else {
    $cb = $_POST['checkbox'];
}

    if (empty($errors)) { 
        $body = "The information sent is as follows:\n\n Company Name: $Cn \n Contact Name: $ln \n Work Address: $add \n Phone: $p \n Email: $e \n I agree to terms: $cb \n\n Comments: $co"; 
        mail ('xxxxxxxx@gmail.com', 'W.E. Can Quit DVD Request', $body, 'From: '.$e);

        echo '<div id="email"><div id="emailSent">
                <h1>Thank you!</h1>
                <p>Your request has been sent.</p>
              </div>';
        echo '<div id="emailSentImg"><img src="images/emailSent.jpg" /></div></div>';

    } else { //Report any collected errors in the errors array.
        echo '<div id="emailNotSent">
            <h1>Error!</h1><br />
            <p>The following error(s) occurred:<br />';
            foreach ($errors as $msg) {
                echo " - $msg<br />\n";
            }
        echo '</p><br /><p>Please use the \'back\' button in your browser and try again.</p>
              </div>';

    } // Ends the empty errors array if.

    } else { // Form has not been submitted; display the form.
    $errors = NULL; 
?>

Here is the email form: 这是电子邮件表格:

<h2>Order Your DVD</h2>
        <div id="dvdForm">
            <form name="form" id="form" method="POST" action="<?php echo $PHP_SELF;?>">
            <table width="550px">
                <tr>
                    <td valign="top">
                        <label for="company_name" class="formText">Company Name:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="company_name" maxlength="50" size="45" value="<?php if (isset($_POST['company_name'])) echo $_POST['company_name']; ?>">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label for="contact_name" class="formText">Contact Name:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="contact_name" maxlength="50" size="45" value="<?php if (isset($_POST['contact_name'])) echo $_POST['contact_name']; ?>">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label for="address" class="formText">Work Address:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="address" maxlength="50" size="45" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label for="phone" class="formText">Phone Number:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="phone" maxlength="12" size="45" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>">
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label for="email" class="formText">Email Address:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="email" maxlength="80" size="45" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>">
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2">
                        <textarea id="myTextArea" rows="4" cols="37" name="comments" value="<?php if (isset($_POST['comments'])) echo $_POST['comments']; ?>"></textarea>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <label for="checkbox">
                        I agree to all of the terms set 
                        out in the <span class="italics">Permission To <br />
                        Use / Reproduce</span> conditions on 
                        the left side of this page.</label>
                    </td>
                    <td valign="top">
                        <input  type="checkbox" name="checkbox" value="Agreed">
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <input type="submit" value="Submit" name="submit">
                    </td>
                </tr>
            </table>
            </form>
        </div>
    <?php } ?>
    </div>                      
</div>
</div>
<?php
    require 'bottomInclude.php';
?>

mail() can be a difficult one to test. mail()可能很难测试。 First you should check whether the function is returning true or false. 首先,您应该检查函数是否返回true或false。 If it is returning true then it is being sent, but its possible the email is getting caught in a spam blocker along the way and never gets to the recipient. 如果返回的是true,则表示它已被发送,但是很可能电子邮件在此过程中被垃圾邮件阻止程序捕获而从未到达收件人。 I had this happen on one of my sites where we sent warning emails to an admin with the domain in the subject. 我在我的一个站点上发生了这种情况,在该站点上我们向主题为域的管理员发送了警告电子邮件。 The hosting company's anti-spam marked our domain name as a spam keyword and no emails would go out if they contained the domain name anywhere in them. 托管公司的反垃圾邮件将我们的域名标记为垃圾邮件关键字,如果其中包含域名的任何电子邮件都不会发送出去。

I also read somewhere that the from address has to be a real email address. 我还在某处读到,发件人地址必须是真实的电子邮件地址。 I have sent emails from an address that didn't exist but might not always work. 我从一个不存在的地址发送了电子邮件,但可能并不总是有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM