0

I've written an simple PHP mail form but it refuses to run on one server but will on another. Both servers are running PHP 5.4 and other PHP progs run on the problematic server but mail will not send.

I've pared the mailer back to the simplest code but am stumped as why one server wont send the mail. Is there a configuration I need to activate or a test I can perform to diagnose the problem?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Simple PHP Mailer</title>
    </head>

    <body>

        <form action="" method="post">
            First Name: <input type="text" name="first_name"><br>
            Last Name: <input type="text" name="last_name"><br>
            Email: <input type="text" name="sender_email"><br>
            Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
            <input type="submit" name="subdata" value="Submit">
        </form>

        <?php   
            //Taken from: http://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on-submit-with-the-same-script

            if(isset($_POST['subdata'])){
                $to = 'myname@gmail.com'; // this is your Email address
                $from = $_POST['sender_email']; // this is the sender's Email address
                $fname = $_POST['first_name'];
                $lname = $_POST['last_name'];
                $subject = "PHP Email Form Test";
                $message = $fname . ' ' . $lname . ' (' . $from . ') wrote the following:' . '\n\n' . $_POST['message'];
                $headers = 'From: user@gmail.com' . "\r\n" .
                'Reply-To: user@gmail.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();

                if (mail($to, $subject, $message, $headers)) {
                    echo 'Mail Sent. Thank you ' . $fname . ', we will contact you shortly.';
                    }else{
                    echo 'Mail Error';
                }

            }
        ?>  
        </body>
</html>

Any help would be appreciated, many thanks. Kw

Kwangle
  • 349
  • 2
  • 15
  • Do you get any error? Have you check the spam folder? – Eduardo Salazar Mar 01 '16 at 04:30
  • The php code reports that the mailto returned false indicating a failure shown by the message echo on screen. On the other server the mail sends and is received normally. – Kwangle Mar 01 '16 at 04:46
  • Check your mail log, eg, `/var/log/mail.log` on Centos. – Eduardo Salazar Mar 01 '16 at 05:05
  • You need an SMTP server installed locally with a `sendmail` binary. Since `mail()` is returning false, there is probably no smtp server set up or sendmail isn't configured properly. – drew010 Mar 01 '16 at 06:07

0 Answers0