我收不到我的电子邮件表格中的邮件

时间:2016-02-15 15:05:09

标签: php email mail-form

所以一切正常,但发送后我没有收到电子邮件并想知道为什么?

不断收到此错误"无法执行邮件投递程序' / usr / local / bin / sendmail -oi -t'在"    HTML

<form action="process.php" method="post">
<ul>
<li>
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" />
</li>
    <li>
    <label for="email">Email:</label>
    <input type="text" name="email" id="email" />
</li>
<li>
<label for="topic">Topic:</label>
<select>
    <option value="optiona">optiona</option>
    <option value="optionb">optionb</option>
    <option value="optionc">optionc</option>
</select>
</li>
<li>
<label for="message">your message:</label>
<textarea id="message" name="message" cols="42" rows="9"></textarea>
</li>
<li><input type="submit" value="Submit"></li>
</form>

PHP

<?php
$to = 'robin.kahrle@gmail.com';
$subject='hi there you';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$message = <<<EMAIL
Hi! My name is $name.
$message
From $name
my email is $email
EMAIL;

$header ='$email';
if($_POST){
mail($to, $subjects, $message, $header);
$feedback = 'Thankyou for your email';
echo $feedback;
 }

 ?>

1 个答案:

答案 0 :(得分:0)

也许您的 $ header $ message 定义不正常。试试这个:

<?php
    // Constants
    $to = 'robin.kahrle@gmail.com';
    $subject='hi there you';

    // Variable contents from the form
    $name =    (!empty($_POST['email'])) ? $_POST['name'] : '????';
    $email =   (!empty($_POST['email'])) ? $_POST['email'] : $to;
    $message = 'Hi? my name is ' . $name;
    if (!empty($_POST['message'])) $message .= . "\r\n" . $_POST['message'];

    // Header
    $header = 'From: ' . $email . "\r\n" .
              'Reply-To: webmaster@example.com' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();

    // Send mail and give feedback
    $accepted = mail($to, $subjects, $message, $header);
    if ($accepted) {
        $feedback = 'Thankyou for your email';
    } else {
        $feedback = 'Email not accepted';
    }
    echo $feedback;