Jump to content

Getting a contact form to work with php


Recommended Posts

Hey guys! So far my website is looking great! Just trying to get this contact form to function. Wondering if everything lines up:

HTML code:

    <section id="contact-form">
    <div class="contact-left">
    <h1 class="c-l-heading"><font style="border-bottom: 3px solid #1ED98B;">Writ</font>e Me</h1>
    <div class="f-name">
    <font >Name</font>
    <input type="text" placeholder="Full Name"/>
    <div class="f-email">
    <font >Email</font>
    <input type="email" placeholder="Example@gmail.com"/>
    <div class="contact-right">
    <div class="message">
    <font >Message</font>
    <textarea name="message" rows="5" cols="20" placeholder="Write Message..."></textarea>



    $name = $_POST['name']; /*this will display the name of the users */
    $visitor_email = $_Post['email']; /*this will display the email of the user */
    $message = $_POST['message']; /*this will store the message */

    $email_from = 'Ryan-vand@outlook.com' /*I will receive this via this line of code */

    $email_subject = "new form submission";

    $email_body = "User Name: $name.\n"."User Email: $visitor_email.\n"."User Message: $message.\n";

    $to = "Ryan-vand@outlook.com";
    $headers = "From: $email_from\r\n";

    header("Location: firstdraft.html");


Link to comment
Share on other sites


You need to add the identifier attributes to your form elements so your PHP code can capture the form data people enter.


<input type="text" id="nameFirst" name="nameFirst">

PHP needs the ID attribute for each form element that captures info. Please refer to the PHP course. 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...