0

I got this free bootstrap temp for a restaurant. And I am trying to make my first contact form, but I have no idea how this works as it is so different from HMTL code.

I take it I have to change the PHP and put my own email address in it at $toEmail but when I try it and test it on XAMPP it does not work.

I have this for my PHP:

<?php
if (isset($_POST['submit'])) { 
  $name = $_POST['name'];
  $email = $_POST['email'];
  $ToEmail = 'test@test.com';
  $EmailSubject = $_POST['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 = "Name: ".$_POST["name"]."<br>"; 
  $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
  $MESSAGE_BODY .= "Subject:".$_POST['subject']."<br />";  
  $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."<br>"; 
  if(mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader))
  {
  echo "<script>alert('Mail was sent !');</script>";
  echo "<script>document.location.href='http://localhost/restaurant/'</script>";
  }
  else
  {
  echo "<script>alert('Mail was not sent. Please try again later');</script>";
  }
 }

And this in my html

<div class="inner contact">
  <!-- Form Area -->
  <div class="contact-form">
    <!-- Form -->
    <form id="contact-us" method="post" action="contact.php">
      <!-- Left Inputs -->
      <div class="col-md-6 ">
        <!-- Name -->
        <input type="text" name="name" id="name" required class="form" placeholder="Naam" />
        <!-- Email -->
        <input type="email" name="email" id="email" required class="form" placeholder="Email Adres" />
        <!-- Subject -->
        <input type="text" name="subject" id="subject" required class="form" placeholder="Onderwerp" />
      </div><!-- End Left Inputs -->
      <!-- Right Inputs -->
      <div class="col-md-6">
        <!-- Message -->
        <textarea name="message" id="message" class="form textarea"  placeholder="Bericht"></textarea>
      </div><!-- End Right Inputs -->
      <!-- Bottom Submit -->
      <div class="relative fullwidth col-xs-12">
        <!-- Send Button -->
        <button type="submit" id="submit" name="submit" class="form-btn semibold">Verstuur Bericht</button> 
      </div><!-- End Bottom Submit -->
      <!-- Clear -->
      <div class="clear"></div>
    </form>
  </div><!-- End Contact Form Area -->             

Can someone please point me in the right direction? Which parts do i need to edit for it to work?

halfer
  • 19,824
  • 17
  • 99
  • 186
daylee
  • 33
  • 1
  • 8
  • 2
    what do you mean with doesnt work? does it send emails at any time? – SpongePablo Jul 10 '15 at 11:31
  • Is the name of your PHP file `contact.php`? – Abey Jul 10 '15 at 11:33
  • Have you got php installed on your server? Perhaps that's the issue. Barring that, yes you will need to do only a bit of editing. I recommend you change the $ToEmail to $ToEmail = $_POST['email'] since $ToEmail is the variable referenced in the mail() method later on. The other $email variable seems redundant. – tllewellyn Jul 10 '15 at 11:34
  • yes its contact php and when i try to send an email it says mail send but then it goes to an object not found page, i`m testing it locally with apache and mysql – daylee Jul 10 '15 at 11:35
  • Yes, apache is your sever, mysql is your database, but do you have php installed on apache? You can verify this by creating a new php page called phpinfo.php with the following lines of code: If it gives you an error message, you likely don't have php installed. – tllewellyn Jul 10 '15 at 11:40

2 Answers2

0

Mail function doesnt work in localhost(XAMPP) you should host it a server and run it

Dhinju Divakaran
  • 893
  • 1
  • 8
  • 11
0

As an alternative to the Dhinju Divakarans answer, you can change the mail server settings to use an external mail server (e.g. gmail)

I did this by editing the /xampp/sendmail/sendmail.ini. look for the following code and change the values. In my case the following works fine:

smtp_server=smtp.googlemail.com
auth_username= (put the gmail email address here)
auth_password= your password
hostname=smtp.googlemail.de

I don't touched the other settings.

Maybe you also want to have a look at this answer.

Community
  • 1
  • 1
AbcAeffchen
  • 14,400
  • 15
  • 47
  • 66