PHP邮件:未收到

时间:2013-09-26 18:08:00

标签: php html forms email expressionengine

好的,我们走了。

因此,我们这个遗留下来的客户显然在我过去没有参与的网站上遇到了电子邮件问题。他们的电子邮件很快被收到,直到(据称!)大约一个月前。

他们最初想要一张表格的验证码,所以我们提供了,但故事情节发生了,他们最终开始收到患者的投诉,试图在网站上填写。所以他们让我们删除它。我的同事简单地评论了验证码部分,并称它为一天。

客户说“无论他们做了什么”都打破了表格,所以现在没有电子邮件通过。好吧,我检查了PHP \ HTML,这一切似乎都在水平..

代码执行得很好,没有给出错误,但没有收到任何错误。所以我认为它可能与服务器有关。

嗯,客户端在服务器上只有一个电子邮件帐户(通过cpanel),而不是与表单关联的帐户。此外,此电子邮件帐户(详情如下)在3个月内未收到任何电子邮件。

他们正在使用WHM \ Cpanel和Cent OS,PHP文件似乎处于良好状态。根据我的研究,防火墙也被配置为允许邮件功能。但是如果我登录他们的电子邮件客户端(roundcube)并尝试发送任何电子邮件我得到错误:

SMTP Error (-1): Connection to server failed.

当我尝试向上述地址发送电子邮件时,它根本就不会到达。

我认为这是完全相关的。

以下是直接来自Expression Engine(1.7.x)的模板代码:

<?php
    session_start();

    //require_once('scripts_server/recaptchalib.php');
    $privatekey = "6LfP7AcAAAAAAGnqNwep55dvYLrgUvJt479b1Vr0";

    error_reporting(0);

    $sent_notice = "";
    $patient_name = "";
    $your_name = "";
    $message = "";
    $error_list = array();

    if(!empty($_POST))
    {
        // Verify the session var is equal (security)
        if( $_SESSION["randomuniquenumber"] != true )
        {
            $error_list[] = "Server Error: Please refresh the page.";
        }

        // Check the names to see if they're empty or invalid
        if(empty($_POST['patient_name'])) {
            $error_list[] = "Please enter the patient's name.";
        }else {
            if(preg_match("/^[-A-Za-z\.\s]+$/", $_POST['patient_name'])) {
                $patient_name = $_POST['patient_name'];
            }else {
                $error_list[] = "Please only use alphabetical characters for names.";
            }
        }
        if(empty($_POST['your_name'])) {
            $error_list[] = "Please enter your name.";
        }else {
            if(preg_match("/^[-A-Za-z\.\s]+$/", $_POST['your_name'])) {
                $your_name = $_POST['your_name'];
            }else {
                $error_list[] = "Please only use alphabetical characters for names.";
            }
        }

        // Check the message is filled out
        if( !empty($_POST['message']) ) {
            if( strlen($_POST['message']) > 1000 ) {
                $error_list[] = "Messages are limited to 1000 characters.";
            }else {
                $message = htmlentities($_POST['message']);
            }                                                                                       
        }
        else {
            $error_list[] = "Please fill out the message field.";
        }



        // Check the re-captcha ------------------------------------------------
        // $resp = recaptcha_check_answer ($privatekey,
         //                                $_SERVER["REMOTE_ADDR"],
          //                               $_POST["recaptcha_challenge_field"],
          //                               $_POST["recaptcha_response_field"]);
        //
        // if (!$resp->is_valid) {
        //  $error_list[] = "The reCAPTCHA wasn't entered correctly.";
        //

                //   }


        // If everything was filled out properly
        if(empty($error_list))
        {
            // Send the email 
            $to = 'mike@madmonkinteractive.com'; //'patientemail@lenoir.org'
            $subject = 'LenoirMemorial.org - Message for a Patient';
            $headers = "From: Via the patient web form at LenoirMemorial.org <patientemail@lenoir.org>";

            $email_message =    'Patient\'s Name: ' . $patient_name . "\n" .
                        'Sender\'s Name: ' . $your_name . "\n\n" .
                        'Message: ' . "\n" . stripslashes($message);

            mail($to, $subject, $email_message, $headers);


                       if(@mail($to, $subject, $email_message, $headers))
                       {
                              echo "<script>javascript: alert('Mail Sent Successfully')></script>";
                               }else{
                             echo "<script>javascript: alert('Mail Failure')></script>";
                        }



            // Now properly escape the data contained in the vars
            $patient_name = mysql_real_escape_string( $patient_name );
            $your_name = mysql_real_escape_string( $your_name );
            $message = mysql_real_escape_string( stripslashes($message) );

            // Connect to the DB and add the the user's info 
            mysql_connect('localhost', 'lenoirm_lenoirm', 'IMz2Aub1qnmX');
            mysql_select_db('lenoirm_lenoirm');

            $date = date("M-j-Y");

            $sql = "INSERT INTO email_patient SET patient_name='".$patient_name."', message='".$message."', your_name='".$your_name."', date='".$date."' ";
            mysql_query($sql) or die(mysql_error());

            session_unset();
            session_destroy();


            // Inform the user that their email has been set
            //header("Location: http://lenoirmemorial.org/index.php/get_in_touch/thank_you/");
        }
    }
    else {
        $_SESSION["randomuniquenumber"] = true;
    }
?>

{embed="includes/header"}
{embed="includes/nav"}
{embed="includes/left_sidebar"}

                <div id="col2">
                    <div class="video-box">
                        <div class="video-top">
                            <div class="video-middle">
                                <h2>Email a Patient</h2>

                                <p><img alt="Brighten Someone's Day" src="/custom/images_content/emailapatient.jpg" style="float: right; margin-left: 10px; margin-right: 10px;" /></p>
                                <p>Would you like to brighten a patient's day with a message of support and encouragement? Stay in touch and let them know you're thinking about them by sending a customized, free email message.</p>
                                <h3>Simple and Easy!</h3>
                                <p>Lenoir Memorial Hospital offers a simple and easy way for friends and family to send free messages to patients. Simply fill out and submit the electronic form below. Our Volunteer Services department will print your email message on special stationery and then deliver it to the patient.</p>
                                <h3>Delivery Information</h3>
                                <p>Email messages are delivered Monday through Friday during regular business hours. Messages received after 1:00 PM may not be delivered until the next business day. We will do our best to deliver messages in a timely manner. We cannot deliver messages to patients who have not been admitted as inpatients or to patients who have been discharged. Please make sure you fill out the patient's first and last name correctly.</p>
                                <h3>Confidentiality</h3>
                                <p>Please remember that email messages are not secure, and the form you will use to send your message is not secure. Members of our volunteer staff will see your message. We maintain the right not to deliver messages that are deemed inappropriate. Due to some sensitivity and confidentiality requirements, email messages will not be delivered to certain units and patients.</p>
                                <p>If you have a question about emailing a patient, please contact us at 252-522-7006.</p>

                                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="email_patient">
                                    <?php
                                        if(count($error_list) != 0) {
                                            foreach($error_list as $error) {
                                                echo '<p class="form_feedback">'.$error.'</p>';
                                            }
                                        }
                                        if($sent_notice != "") {echo $sent_notice;}
                                    ?>
                                    <ul>
                                        <li>
                                            <label for="patient_name">Patient's First and Last Name:</label>
                                            <input type="text" name="patient_name" value="<?php if($patient_name != "") echo $patient_name; ?>" id="patient_name" />
                                        </li>
                                        <li>
                                            <label for="your_name">Your Name:</label>
                                            <input type="text" name="your_name" value="<?php if($your_name != "") echo $your_name; ?>" id="your_name" />
                                        </li>
                                        <li>
                                            <label for="message">Message (1000 Character Limit):</label>
                                            <textarea name="message" rows="8" cols="40"><?php if($message != "") echo stripslashes($message); ?></textarea>
                                        </li>
                                        <li>
                                            <?php
                                                //$publickey = "6Len9wYAAAAAAIzFGpc_paC-F_88OftuRiw3UyWt";
                                                //$publickey = "6LfP7AcAAAAAAENozkyqiIOGqVdkNI_ea8UmEctu";
                                                // echo recaptcha_get_html($publickey);
                                            ?>
                                        </li>
                                        <li>
                                            <input type="submit" name="submit" value="Submit" id="submit" />
                                        </li>
                                    </ul>
                                </form>

                            </div>
                        </div>
                        <div class="video-bottom">
                            &nbsp;
                        </div>
                    </div>
                </div>

{embed="includes/news_events_sidebar"}
{embed="includes/footer"}

编辑:执行此代码,我收到正在打印的消息“错误”...

 $result = mail($to, $subject, $email_message, $headers);
                           if(!$result) {   
                                              echo "Error";   
                           } else {
                                              echo "Success";
                          }

0 个答案:

没有答案