1

This is my first post, hopefully there is a simple answer:

So as per the topic title, I cannot get my form to send an email.

This is the HTML code:

                <form method="post" action="email.php">
                <div class="row half">
                    <div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div>
                    <div class="6u"><input type="text" class="text" name="email" placeholder="Email" /></div>
                </div>
                <div class="row">
                    <div class="12u"><input type="text" class="text" name="subject" placeholder="Subject" /></div>
                </div>
                <div class="row half">
                    <div class="12u">
                        <textarea name="message" placeholder="Message"></textarea>
                    </div>
                </div>
                <div class="row">
                    <div class="12u">
                        <ul class="actions">
                            <li><input type="submit" value="Send Message" /></li>
                            <li><input type="reset" value="Reset" name="reset"/></li>
                        </ul>
                    </div>
                </div>
            </form>

Here is the PHP code:

<?php
  //Required Input Fields

    $name = check_input($_POST['name'], "<p>Please Enter Your Name!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $email = check_input($_POST['email'], "<p>Please Enter Your Email Address!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $subject = check_input($_POST['subject'], "<p>Please Enter a Subject!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $message = check_input($_POST['message'], "<p>Please Enter Your Message!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");

  //Html Error

    $SpamErrorMessage = "<p>No Website URLs Permitted!</p><br  /><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>";
    if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$subject")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}

  //Email Validation

    $email = htmlspecialchars($_POST['email']);
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
    {
      die("<p>We're Sorry, Your Email Address Does Not Appear to Be Valid.</p><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>");
    }

  //Function Check to Eliminate Unwanted Characters, Strips Quotes, and Adds HTMLSpecialCharacters

    function check_input($data, $problem='')
    {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      if ($problem && strlen($data) == 0)
      {
         die($problem);
      }
      return $data;
    }

  //Sends Email and Forwards to Thank You Page

    mail('*****@gmail.com', $subject, $message, '-f$email');
        echo "<h2><p>Thank you for your message. <br  /> We will reply back to you shortly.</h2><p><a href='http://www.*****.co.uk' class='button style2 scrolly scrolly-centered'>Click here to return</a></p>";
?>

Can anyone work out what could be wrong? The server that the code is running on does not have an SMTP server. Is this what could be causing the code to fail?

Thank You

Metz
  • 11
  • 3
  • Did you take a look in your spam folders? Sometimes gmail can be overzealous with it's filtering... – Lix Aug 20 '14 at 15:17
  • Yes, the fact that you don't have SMTP configured is why. – tbddeveloper Aug 20 '14 at 15:18
  • What platform are you running this on? if its windows you need to setup an SMTP server, or connect to an SMTP server via php.ini, if its linux you can use sendmail to forward to an smtp server, but you will need to tell PHP where the sendmail path is in php.ini – RaggaMuffin-420 Aug 20 '14 at 15:23
  • I am using Windows server 2012 Running IIS, I used the Microsoft Web Platform installer to install PHP. I don't actually know where that saves the php.ini file :-/ – Metz Aug 20 '14 at 15:48

0 Answers0