0

Please can anyone see any errors in this PHP code, I have tried everything I can think of with no luck, I am trying to get a form to send the data to the PHP and then send an email but every time I try on the server all I get is the 'Message failed.'

 <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];

    $mail_to = 'MyEmail@hotmail.co.uk';
    $subject = 'Message from a site visitor '.$field_name;

    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;

    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";

    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) { ?>
        <script language="javascript" type="text/javascript">
            alert('Thank you for the message. We will contact you shortly.');
            window.location = 'default.html';
        </script>
    <?php
    }
    else { ?>
        <script language="javascript" type="text/javascript">
            alert('Message failed.');
            window.location = 'default.html';
        </script>
    <?php
    }
    ?>
Michael Jones
  • 33
  • 2
  • 6
  • @GregValcourt: Then why not `Python` ? –  Feb 13 '16 at 15:41
  • I think you work on localhost not in server. So mail function is always return false. Did you configure any mail server? – Tamil Selvan C Feb 13 '16 at 15:42
  • Is your message contain some special characters?? – Murad Hasan Feb 13 '16 at 15:53
  • check out default: `mail("MyEmail@hotmail.co.uk","My subject", "Your message");` if its work then go for the problem. if it is not working then find out the problem of your mailing server. – Murad Hasan Feb 13 '16 at 15:55
  • From PHP Doc: It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination. – fusion3k Feb 13 '16 at 16:01

0 Answers0