user3693134
user3693134

Reputation: 23

PHP mail is not sending email to my email address

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 = "[email protected]";
    $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("[email protected]",$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).

Upvotes: 2

Views: 268

Answers (1)

Paul Dessert
Paul Dessert

Reputation: 6389

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

Upvotes: 1

Related Questions