PHP form phone input not working

Discussion in 'Coding Help' started by links, Nov 14, 2011.

  1. links

    links New Member

    I am trying to create a form that has, Name, Phone, Email, address and when such as month.

    Currently the name, email is working but the rest are not. Can someone assist please

    PHP code:

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

    $mail_to = '';
    $subject = ' booking form '.$field_name;

    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'Phone: '.$field_phone."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Address: '.$field_address."\n";

    $body_message .= 'when: '.$field_message."\n";

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

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

    if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you. We will contact you shortly.');
    window.location = ' thankyou.html ';
    else { ?>
    <script language="javascript" type="text/javascript">
    alert('Message failed. Please, send an email to');
    window.location = 'thankyou.html';

    Html code:

    <form action="popup.php" method="post">
    Your name<br>
    <input type="text" name="cf_name"><br>

    Your number<br>
    <input type="phone" name="cf_phone"><br>

    Your e-mail <br>
    <input type="text" name="cf_email"><br>

    Address <br>
    <input type="text" name="cf_address"><br>

    When last cleaned <br>
    <input type="text" name="cf_when"><br>

    <input type="submit" value="Send">
    <input type="reset" value="Clear">
  2. php.allstar

    php.allstar New Member


    This should see you through....

    It's not the way I would handle an email form myself but whatever rocks your boat!

    By the way, as the script stands, it is vulnerable to email header injection which if a bot cops on to, you will find your server resources getting drained while your server is sending out spam emails to everyone!

    <?php if($_POST){

    $field_name $_POST['cf_name'];
    $field_email $_POST['cf_email'];
    $field_phone $_POST['cf_phone'];
    $field_address $_POST['cf_address'];
    $field_message $_POST['cf_when'];

    // You really should do some email header injection prevention (with the above variables) here...

    $mail_to '';
    $subject ' booking form '.$field_name;

    $body_message 'From: '.$field_name."\n";
    $body_message .= 'Phone: '.$field_phone."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Address: '.$field_address."\n";

    $body_message .= 'when: '.$field_message."\n";

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

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

        if (
    $mail_status) { ?>

            <script language="javascript" type="text/javascript">
            alert('Thank you. We will contact you shortly.');
            window.location = ' thankyou.html ';

        <?php } else { ?>

            <script language="javascript" type="text/javascript">
            alert('Message failed. Please, send an email to

            window.location = 'thankyou.html';

        <?php ?>

    <?php ?>

    <form action="popup.php" method="post">
        Your name<br>
        <input type="text" name="cf_name"><br>

        Your number<br>
        <input type="phone" name="cf_phone"><br>

        Your e-mail <br>
        <input type="text" name="cf_email"><br>

        Address <br>
        <input type="text" name="cf_address"><br>

        When last cleaned <br>
        <input type="text" name="cf_when"><br>

        <input type="submit" value="Send">
        <input type="reset" value="Clear">

  3. links

    links New Member

    I appreciate it and thanks for the assistance. It has worked . I will take your advice and look at a different way for the email form. What way would you recommend ?

Share This Page