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 = '[email protected]';
    $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

0 Answers0