Results 1 to 3 of 3

Thread: adding phone number field to existing contact form.

  1. #1
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default adding phone number field to existing contact form.

    This is my send.php
    Code:
    <?php
    $to = email@email.com"; //Your email goes here
    
    $name = stripslashes($_POST["name"]);
    $email = stripslashes($_POST["email"]);
    $subject = stripslashes($_POST["name"]);
    $message = stripslashes($_POST["message"]); 
    
    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/plain; charset=utf-8" . "\r\n";
    $headers .= "From: $name <$email>" . "\r\n";
    
    if(mail($to, $subject, $message, $headers)){
    	echo "Your message was sent! Thank you."; //This message gets display to user on success
    }else{
    	echo "Sorry, your message wasn't sent. Try again or contact me at $to"; //Message displayed to user on failure
    }
    ?>
    and this is my contact form.
    Code:
      <h1 class="header">Contact form</h1>
            <form id="contact-form" action="">
    	        <div>
                <label for="form_name">Name</label>
                <input id="form_name" name="name" type="text" /><br />
              </div>
              <div>
                <label for="form_email">Email</label>
                <input class="vemail" id="form_email" name="email" type="text" /><br />
              </div>
               <div>
                <label for="phone">Phone #</label>
                <input class="phone" id="phone" name="phone" type="text" /><br />
              </div>
             
              <div>
                <label for="form_message"></label>Comment<br /><br />
                <textarea id="form_message" name="message" rows="5" cols="10"></textarea><br />
    	        </div>
    	        <div>
                <input id="send_contact" type="image" src="images/submit.png" />
              </div>
            </form>
    This contact form is working fine, it sends to my email address, but I need to include the phone number in the body of the email. I know i added the phone number field alreaday. But I need help getting it on send.php
    Can someone help please.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I think changing the $message to

    PHP Code:
    $message stripslashes($_POST["message"] . $_POST["phone"]); 
    will do it
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    or
    PHP Code:
    $message stripslashes($_POST['message'] . "<br>Phone Number: " $_POST['phone']); 
    to make it a little more readable

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •