PHP发送邮件脚本不适用于PHP版本5.3.10-1ubuntu3.15

时间:2015-10-29 17:30:48

标签: php ubuntu post sendmail

我下面的sendmail脚本适用于PHP 5.6.14版本,但是我必须在版本为5.3.10的服务器上使用相同的脚本而且它不会发送。我是否需要更改代码的语法才能使用旧的PHP?如果是这样我需要改变什么?

  
            <?php

            $error = ""; // Initialize error as blank
            $errorMsg = ""; // Initialize error as blank

            if (isset($_POST['submit'])) { // check if the form is submitted
                #### removing extra white spaces & escaping harmful characters ####
                $name               = trim($_POST['name']);
                $email              = $_POST['email'];
                $phone              = $_POST['telephone'];
                $company              = $_POST['company'];
                $message         = $_POST['message'];


                #### start validating input data ####
                #####################################


                # Validate First Name #
                    // if its not alpha numeric, throw error
                if (!ctype_alpha(str_replace(array("'", "-"), "",$name))) { 
                    $error .= '<p class="error">Name should be alpha characters only.</p>';
                }
                    // if first_name is not 2-50 characters long, throw error
                if (strlen($name) < 2 OR strlen($name) > 50) {
                    $error .= '<p class="error">Name should be within 2-50 characters long.</p>';
                }


                # Validate Email #
                    // if email is invalid, throw error
                    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // you can also use regex to do same
                        $error .= '<p class="error">Enter a valid email address.</p>';
                    }

                # Validate Phone #
                    // if phone is invalid, throw error
                    if ($phone == "") {

                    } elseif ($phone != "") {

                        if (!ctype_digit($phone) OR strlen($phone) != 10) {
                            $error .= '<p class="error">Enter a valid phone number.</p>';
                        }

                    }

                # Validate Dealer select #
                    // if select dealer is empty, throw error


                    if(empty($messgae))
                    {
                        $error .= '<p class="error">Select a subject.</p>';
                        //$error=true;
                    }



                #### end validating input data ####
                #####################################

            }


                if($name === "" || $email === "" || $subject === ""){

                    $errorMsg = "Please go back and make sure you have filled out the form correctly";

                } else {   



                   if(isset($_POST["name"])) {

                    // Build the message body
                      $body .= "Name: ".$_POST["name"]."\n";
                      $body .= "Email: ".$_POST["email"]."\n";
                      $body .= "Phone: ".$_POST["telephone"]."\n";
                      $body .= "Company: ".$_POST["company"]."\n";
                      $body .= "Subject: ".$_POST["subject"]."\n";


                    if (isset($_POST['contact'][0])) {
                        $body .= "Can be contacted by email."."\n";
                    }

                    if (isset($_POST['contact'][1])) {
                        $body .= $_POST["subject"];
                    } 


                    $body = wordwrap($body, 70);

                    $subject                = $_POST["subject"];
                    $addr_from          = "info@tandsadvertising.co.uk";

                    require_once('config.php'); 

                    /*define('__ROOT__', dirname(dirname(__FILE__))); 
                    require_once(__ROOT__.'config.php'); */

                    $sendmail = mail($addr_to, $subject, $body, "From:" . $addr_from . "\n", "-f" . $addr_from );

                    if($sendmail)   header("Location: /form/thankyou.php");
                    else { echo "send mail failed, please check settings"; }
                }

            }


            ?>

0 个答案:

没有答案
相关问题