PHP从在线表单发送电子邮件

时间:2014-04-24 13:11:30

标签: php html

我创建了一个页面,允许用户将他们的信息放在表单中并发送给网站管理员。但是,它不会将电子邮件发送到管理员电子邮件。 HTML代码是:

<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  ">

    

PHP代码是:

<?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("my@email.com",$from,$last,$make,$model,$reg,$em,$subject,"From: $form<auto-reply@$host>");
        print "Thank you for sending us feedback";
    }
}
?>
</body>
</html>

1 个答案:

答案 0 :(得分:3)

试试这个

<?php
$to = "my@email.com";
$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: from@email.com' . "\r\n";
 mail($to,$subject,$message,$headers);
 header("Location: http://successurlgoeshere.com");
 ?>