为什么我无法从联系表中看到电子邮件地址?

时间:2018-12-07 17:02:39

标签: php html forms email contacts

我收到了一封电子邮件,但会从未知中读取。其他一切似乎都起作用。这是指向页面link的链接,我对php不太了解。

    <?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $mailTo = "contact@podmtg.com";
    $headers = "From: ".$mailFrom;
    $txt = "You have recieved an email from ".$name.".\n\n".$message;

    mail($mailTo, $subject, $txt, $headers);

    header("Location: contact.html?mailsend");
}

?>

<form action="contactform.php" method="post" onsubmit="return confirm('Are you sure you want to submit this form?');">
             <input type="text" name="name" placeholder="Name" required="required">
             <input type="text" name="email" placeholder="Email" required="required">
             <textarea name="message" placeholder="Write message here..." required="required"></textarea>
             <button type="submit" name="submit">SUBMIT</button>
        </form>

2 个答案:

答案 0 :(得分:2)

在此您提到了`$ headers =“ From:”。$ mailFrom;。但找不到$ mailFrom。使用$ email代替$ mailFrom。

答案 1 :(得分:0)

我更改了密码。你们是对的。谢谢!

    <?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $mailFrom = $_POST['email'];
    $message = $_POST['message'];

    $mailTo = "contact@podmtg.com";
    $headers = "From: ".$mailFrom;
    $txt = "You have recieved an email from ".$name.".\n\n".$message;

    mail($mailTo, $headers, $txt);

    header("Location: index.html?mailsend");
}

?>