PHP send mail script not working with PHP version Version 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"]."\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"; }
                }

            }


            ?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s