【问题标题】:PHP sending email from online formPHP 从在线表单发送电子邮件
【发布时间】:2014-06-09 19:12:48
【问题描述】:

我制作了一个页面,允许用户将他们的信息放入表单中并将其发送给网站管理员。但是,它不会将电子邮件发送到管理员电子邮件。 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>

【问题讨论】:

  • 这可能是服务器配置的问题
  • 它抛出了什么错误?你能看看你的error_log吗?
  • 它没有显示任何错误@thedjaney
  • 尝试在顶部显示错误以防万一:error_reporting(E_ALL); ini_set('display_errors', 1);

标签: php html


【解决方案1】:

试试这个

<?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");
 ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    相关资源
    最近更新 更多