dongxian3852 2015-10-29 17:30
浏览 31

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

The sendmail script I have below works on PHP version 5.6.14, but i've had to use the same script on a server that has version 5.3.10 and it just won't send. Do i need to change the syntax of my code to work with older PHP? if so what do i need to change?

            <?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"]."
";
                      $body .= "Email: ".$_POST["email"]."
";
                      $body .= "Phone: ".$_POST["telephone"]."
";
                      $body .= "Company: ".$_POST["company"]."
";
                      $body .= "Subject: ".$_POST["subject"]."
";


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

                    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 . "
", "-f" . $addr_from );

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

            }


            ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效