user2402688
user2402688

Reputation: 1

php form submitted, but no email received

I am attempting to send an email by filling out a contact form. Both my html form and php file are included below. Once I fill out the form, it notifies me that the email has been sent. However, I never receive an email; I cannot figure out what i am doing wrong.

This is my html form:

<div class="row" style="padding-top:27px">
            <div class="large-6 column">
                <form action="mail.php" method="POST" data-abide>



                    <div class="name-field">
                        <label>Your name*</label>
                        <input type="text" required pattern="[a-zA-Z]+">
                            <small class="error">Name is required and must be a string.</small>
                            </div>

                    <div class="email-field">
                        <label>Email*</label>
                        <input type="email" required>
                            <small class="error">An email address is required.</small>
                            </div>

                    <div>
                        <label> Subject* </label>
                        <!--<input class="error" type="subject" name="subject" value="" size="40" required>
                            <small class="error">Invalid entry</small>-->
                    <select id="customDropdown1" class="medium error" required="" data-invalid="">
                            <option value="">Select an option...</option>
                            <option value="first">Green Chilies</option>
                            <option value="second">Raisins</option>
                            <option value="third">Panko bread crumbs</option>
                            <option value="fourth">Assistance</option>
                        </select>
                        <small class="error">Invalid entry</small>
                            </div>



                </div>


            <div class="large-6 column">
               <!-- <label> Message </label>
                <textarea class="error" placeholder="Message..." id="info" class="message" name="message" cols="70" rows="60" size="90" requi></textarea><br>-->

               <label> Message </label>
               <textarea class="error" placeholder="Message..." ></textarea>
               <small class="error">Invalid entry</small>

                <div>

                    <input style="float:right;" type="submit" value="Submit">
                        <img style="visibility: hidden;">



                            </div>



                      </form>

This is my php file:

<?php
$to = "[email protected]";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";

mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>

UPDATED FILES:

HTML:

                <div class="name-field">
                    <label>Your name*</label>
                    <input type="text" name="name" required pattern="[a-zA-Z]+">
                        <small class="error">Name is required and must be a string.</small>
                        </div>

                <div class="email-field">
                    <label>Email*</label>
                    <input type="email" name="email" required>
                        <small class="error">An email address is required.</small>
                        </div>

                <div>
                    <label> Subject* </label>
                    <!--<input class="error" type="subject" name="subject" value="" size="40" required>
                        <small class="error">Invalid entry</small>-->
                <select id="customDropdown1" class="medium error" name="subject" required="" data-invalid="">
                        <option value="">Select an option...</option>
                        <option value="first">Green Chilies</option>
                        <option value="second">Raisins</option>
                        <option value="third">Panko bread crumbs</option>
                        <option value="fourth">Assistance</option>
                    </select>
                    <small class="error">Invalid entry</small>
                        </div>



           <!-- End Contact Form -->
            </div>

PHP:

<?php
$to = "[email protected]";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>

Upvotes: 0

Views: 239

Answers (2)

Andrew Brown
Andrew Brown

Reputation: 5424

The fourth parameter of mail() is additional headers. Which is where your "FROM" information should go.

Refer here: http://php.net/manual/en/function.mail.php

for what should go there.

here's one example

$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Upvotes: 0

Brian Phillips
Brian Phillips

Reputation: 4425

None of your input fields have a name associated with them, so you're likely getting empty data in your POST. The 'email' value within $_POST['email'] refers to an input field's name.

Specifically, you're not getting an email address from your form, so the email is not sending to anyone.

For instance, you'll need:

<input type="email" name="email" required>

Upvotes: 1

Related Questions