-2

I am very new to coding and am trying to set up a contact form using code from here: http://codepen.io/rexkirby/pen/Fdnlz

I now need to make it functional but have 0 knowledge of php. I've tried lots of different bits of php code, but I don't even know how to link the html file to the .php file properly. My code is below, if anyone could tell me how to link the files I would be so so grateful!

HTML:

<div id="form-main">
  <div id="form-div">
    <form class="form" id="form1" action="mail.php" method="post">
      <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
      </p>

      <p class="email">
        <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
      </p>

      <p class="text">
       <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Comment"></textarea>
      </p>
      <div class="submit">
        <input type="submit" value="SEND" id="button-blue"/>
          <div class="ease"></div>
      </div>
    </form>
</div>

Php

    <?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
    //send email
    $from = $_REQUEST['author'] ;
    $to = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['msg'] ;
    mail($to, $subject, $message, "From:" . $from);

    // the mail was sent
    echo "Thank you for using our mail form";
}
else {
    //if "email" is not filled out, display the form
    //just close php and copy the code for your form
?>
Livb
  • 13
  • 4
  • Where is your `mail.php` file? – AndrewL64 Apr 25 '16 at 15:53
  • The `action` attribute tells the form where to send the data. So `action="mail.php" ` is sending the form's data to a script called `mail.php`. Did you make that file and populate it? – chris85 Apr 25 '16 at 15:55
  • 1
    What attempt have you made? What isn't working as expected? Currently your question is basically "Teach me PHP", which is *far* too broad for Stack Overflow. – David Apr 25 '16 at 15:56
  • if you didn't have little bit knowledge about php you didn't have understand what to do discus with friends who knows about php i'm sure you will get success soon. – Yaseen Ahmad Apr 25 '16 at 15:56
  • the "action" from your form is "where" you have to send your form data. Check that is well linked to "mail.php" – Roger Guasch Apr 25 '16 at 15:57
  • My mail.php file is in the same folder as my html and css files which are successfully linked to each other. But clicking the send on the contact form shows a white page with the code...:S – Livb Apr 25 '16 at 16:40
  • So your PHP has an error. Look at your error logs. – chris85 Apr 25 '16 at 16:45
  • I've updated the question to show the php – Livb Apr 25 '16 at 16:48

2 Answers2

1

Thanks! I finally sorted the problem, it turns out GitHub doesn't support php which is where I was hosting it

Livb
  • 13
  • 4
0

First create a file called mail.php and place it within the same directory as your html/css file.

The mail.php file is responsible for processing your form and then sending it wherever you wish. Save these files and simply test them on a web server like WAMP/LAMP/XAMP or a live server if you have one.

Dannyw24
  • 61
  • 8