PHP form phone input not working

Status
Not open for further replies.

links

New Member
Hi,
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:



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


$mail_to = 'test@eircom.net';
$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 ';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to


test@eircom.net');
window.location = 'thankyou.html';
</script>
<?php
}
?>





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">
</form>
 

php.allstar

New Member
Hi,

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:
<?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 = 'test@eircom.net';
    $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 ';
        </script>

    <?php } else { ?>

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

        test@eircom.net');
        window.location = 'thankyou.html';
        </script>

    <?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">

</form>
 

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 ?
 
Status
Not open for further replies.
Top