POST输入邮件()

时间:2013-12-29 11:04:56

标签: php email variables

echo '<div id="email">
            <form action="#" method="POST">
                <label>E-mailadres:</label>
                <p><input type="text" name="mail1" value="me@me.nl"> </p>
                <input type="submit" name="submitemail"> 
            </form>
    </div>';

    $to = 'MY@MAIL.COM';
    $lala = $_POST['mail1'];

    // subject
    $subject = 'Subject';

    // message
    $message = $selected . $totaal .'';

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= 'From: ' . $lala . ' <' . $lala . '>';

    // Mail it
    mail($to, $subject, $message, $headers);

发送电子邮件工作正常,它只是不会抓住插入的电子邮件。

我无法将<input .... name="mail1">(me@me.nl)的值输入“FROM:”部分。

我错了什么或在这种情况下我不做的事情是什么?


每当使用$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";时,它都能完美运作。

1 个答案:

答案 0 :(得分:1)

尝试

echo '<div id="email">
            <form action="a.php" method="POST">
                <label>E-mailadres:</label>
                <p><input type="text" name="mail1" value="me@me.nl"> </p>
                <input type="submit" name="submitemail"> 
            </form>
    </div>';
if (isset($_POST['submitemail'])) {
    $to = 'MY@MAIL.COM';
    $lala = $_POST['mail1'];

    // subject
    $subject = 'Subject';

    // message
    $message = $selected . $totaal . '';

    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $headers .= 'From: ' . $lala . ' <' . $lala . '>';

    // Mail it
    mail($to, $subject, $message, $headers);
}

a.php是你的php文件的名称