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

时间:2014-03-14 13:40:24

标签: php html forms email

任何人都可以帮我弄清楚为什么这封电子邮件表格不会发送电子邮件?我已经与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; 
?>

以下是电子邮件表单:

<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';
?>

1 个答案:

答案 0 :(得分:0)

mail()可能很难测试。首先,您应该检查函数是返回true还是false。如果它返回true则会被发送,但可能是电子邮件在此过程中被垃圾邮件拦截器捕获并且永远不会到达收件人。我在我的一个网站上发生了这种情况,我们向主管中的域管理员发送了警告电子邮件。托管公司的反垃圾邮件将我们的域名标记为垃圾邮件关键字,如果域名中包含域名,则不会发送任何电子邮件。

我还在某处读到,地址必须是真实的电子邮件地址。我从一个不存在但可能并不总是有效的地址发送了电子邮件。