user3568955
user3568955

Reputation: 9

PHP sending email from online form

I have made a page which allows users to put their information in a form and send it off to the admin of the website. However it does not send the email to the admin email. The HTML code is:

<div class="quote">  
<form name="quoteform" id="qf" method="post" action="quote1.php">
    <label>
    First Name*:
    <input type="text" placeholder="Please enter First Name here" name="from" class="input" required >
    </label>

    <label>
    Last Name*:  
    <input type="text" placeholder="Please enter Last Name here" name="last" class="input" required>
    </label>

    <label>
    Vehical Make*:
    <input type="text" placeholder="Please enter Vehicle Make" name="make" class="input" required>
    </label>

     <label>
    Vehical Model*:
    <input type="text" placeholder="Please enter Vehicle Model" name="model" class="input" required>
    </label>
     <label>
    Vehical Registration Number:
    <input type="text" placeholder="Please enter Registration Number" name="reg" class="input" required>
    </label>
     <label>
    Email Address*:
    <input type="email" placeholder="Please enter Email Address" name="em" class="input" required>
    </label>
    <label>
    Enter Your Enquiry*:
    <textarea rows="4" cols="45" name="message" placeholder="Enter your Enquiry here..." class:"input" required></textarea>
    </label>
    <input class="sendButton" type="submit" name="Submit" value="  Submit  ">

The PHP code is:

<?php
$host  = $_SERVER['HTTP_HOST'];

if (!isset($_POST["submit"])) {
?>
<?php 
} else {    // the user has submitted the form
    // Check if the "from" input field is filled out
    if (isset($_POST["from"])) {
        $from = $_POST["from"]; // sender
        $last = $_POST["last"];
        $make = $_POST["make"];
        $model = $_POST["model"];
        $reg = $_POST["reg"];
        $em = $_POST["em"];
        $subject = $_POST["subject"];
        // message lines should not exceed 70 characters (PHP rule), so wrap it
        $message = wordwrap($message, 70);
        // send mail
        mail("[email protected]",$from,$last,$make,$model,$reg,$em,$subject,"From: $form<auto-reply@$host>");
        print "Thank you for sending us feedback";
    }
}
?>
</body>
</html>

Upvotes: 1

Views: 104

Answers (1)

KM123
KM123

Reputation: 1387

Try This

<?php
$to = "[email protected]";
$subject = "My Subject Line";

$message = '<html>
<body>
 First NAME-------- ' . strip_tags($_POST["from"]) . '<br>
 Last NAME-------- ' . strip_tags($_POST["last"]) . '<br>
 MAKE-------- ' . strip_tags($_POST["make"]) . '<br>
 MODEL -------- ' . strip_tags($_POST["model"]) . '<br>
 REG-------- ' . strip_tags($_POST["reg"]) . '<br>
 EMAIL -------- ' . strip_tags($_POST["em"]) . '<br>
 Message-------- ' . strip_tags($_POST["message"]) . '<br>
</body>
</html>';
 $headers = "MIME-Version: 1.0" . "\r\n";
 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
 $headers .= 'From: [email protected]' . "\r\n";
 mail($to,$subject,$message,$headers);
 header("Location: http://successurlgoeshere.com");
 ?>

Upvotes: 3

Related Questions