Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form php script build.. help?

Featured Replies

Hello,
I am no php expert and I have only ever made 1 contact form YEARSSSS ago!
so, this is where I am at currently on my own php contact form.
Is this acceptable? I am running my site on a MAMP so I do not know if this is working?
I have built my form and I want my php code to work with this form. I have tried adapting a script around it.. Can someone help me out with creating this script?

 

   <?php 
    if ($_POST["email"]<>'') { 
        $ToEmail = 'someone@email.com'; 
        $EmailSubject = 'Email Subject'; 
        $mailheader = "From: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        $MESSAGE_BODY = "First Name: ".$_POST["first_name"].""; 
        $MESSAGE_BODY = "Last Name: ".$_POST["last_name"].""; 
        $MESSAGE_BODY .= "Email: ".$_POST["email_address"].""; 
        $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"]).""; 
        mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
    ?> 
    <h4>Your message was sent</h4>
    <?php 
    } else { 
    ?> 
    
    <form class="well span8 offset2" action="/contact/index.php" method="POST">
      <div class="row">
            <div class="span3">
                <label>First Name</label>
                <input type="text" name="first_name" id="first_name" class="span3" placeholder="Your First Name" >
                <label>Last Name</label>
                <input type="text" name="last_name" id="last_name" class="span3" placeholder="Your Last Name" >
                <label>Email Address</label>
                <input type="text" name="email_address" id="email_address" class="span3" type="email" placeholder="Your email address" >
            </div>
            <div class="span5">
                <label>Message</label>
                <textarea name="message" id="message" class="input-xlarge span5" rows="10" ></textarea>
            </div>
        
            <button type="submit" class="btn btn-success pull-right">Send</button>
        </div>
    </form>
    
    <?php 
    }; 
    ?>

 

 

If anyone with more experience can hand me a php script that they use? Or something to fit around my form. The form is included in the 2nd part of my code posted above. The framework I am working on is Bootstrap.
Thanks!

You really want to do some validation on the form data. Look up php's filter_var - it makes validating email addresses easy. You will also want to ensure that your required fields are filled in, do some anti-spam processing and display helpful error messages. Look up htmlspecialchars() and strip_tags().

 

As coded, you won't get the expected results because you've used $_POST['email'] and $_POST['email_address']. $_POST['email'] will never exist the way you've coded your form.

 

One other thing, its bad form to use uppercase for variables.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.