2

I've been looking around everywhere and cannot seem to find how to make this work - it is simply not sending an email to my address. Here is my HTML form:

<form id="contactMe" name="contact" method="post" novalidate="novalidate">
    <fieldset>
        <label for="name" id="name">Name<span class="required">*</span></label>
            <input type="text" name="name" id="name" size="30" value="" required="">
            <label for="email" id="email">Email<span class="required">*</span></label>
            <input type="text" name="email" id="email" size="30" value="" required="">
            <label for="phone" id="phone">Phone</label>
            <input type="text" name="phone" id="phone" size="30" value="">
            <label for="Message" id="message">Message<span class="required">*</span></label>
            <textarea name="message" id="message" required=""></textarea>
            <label for="Answer" id="answer">Name the house pet that says “<i>woof</i>“<span class="required">*</span></label>
            <input type="text" name="answer" value="" required=""></br>
            <input id="submit" type="submit" name="submit" value="Send">
        </fieldset>
        <div id="success">
            <span class="green textcenter">
            <p>Your message was sent successfully! I will be in touch as soon as I can.</p>
            </span>
        </div> <!-- closes success div -->
        <div id="error">
            <span><p>Something went wrong, try refreshing and submitting the form again.</p></span>
        </div> <!--close error div-->
    </form>

and here is my PHP saved as mailer.php:

<?php

    $to = "someone@gmail.com";
    $from = $_REQUEST['email'];
    $name = $_REQUEST['name'];
    $headers = "From: $from";
    $subject = "You have a message from your.";

    $fields = array();
    $fields{"name"} = "name";
    $fields{"email"} = "email";
    $fields{"phone"} = "phone";
    $fields{"message"} = "message";

    $body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    mail("maytee.kneitz@gmail.com",$subject,$message,"From: $from\n");
    echo 'Mail sent';

?>

This is my first shot at working on a mailer / contact form, so sorry if it's a blatant problem. I just can't seem to find it. Any guidance would be appreciated.

I do have validation in my scripts (not posted here).

David Corbin
  • 524
  • 2
  • 11
  • 25
  • Do you have a mail server installed? – Paul Dessert May 30 '14 at 23:51
  • and are you sure you're not being seen as spam or being stopped by the outgoing server since you're trying to send mail from a different server than your from header? (sending From: someone@some-other-domain.com) You may want to change that to reply-to and omit from or change from to something like do-not-reply@your-domain.com ... or use something like swift mailer since it is already superior to hand made.http://swiftmailer.org/ – Kai Qing May 30 '14 at 23:53
  • I checked my spam and its not in there. I'm using dreamhost as my hosting service and have tried routing it to several email addresses and it just won't go. – user3693134 May 30 '14 at 23:56
  • Do you know that your `$_REQUEST` array has an email and name key and that they are correct? – David Corbin May 30 '14 at 23:58
  • @user3693134 have a read of http://www.damonkohler.com/2008/12/email-injection.html http://stackoverflow.com/questions/1055460/how-to-sanitze-user-input-in-php-before-mailing unless you want spammers pawning your server – Lawrence Cherone May 30 '14 at 23:59

1 Answers1

1

You don't have a form action defined. Try this:

<form id="contactMe" name="contact" method="post" action="mailer.php" novalidate="novalidate">

By default, the form will be submitted to its current location unless otherwise specified. In your case, point it to wherever your mail script is located

Paul Dessert
  • 6,363
  • 8
  • 47
  • 74