我的联系表单存在问题。当用户点击发送电子邮件按钮时,我会收到带有标题的电子邮件,但我无法看到用户的输入。
所以基本上我能够看到标题($ subject)和预先写好的文本("这是一个自动消息"),但我无法看到$ email和$的内容信息。可能有什么不对?
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test@testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
答案 0 :(得分:1)
您需要检查是否有帖子参数然后发送电子邮件
将您的代码更改为
<?php
if(isset($_POST['email']) && isset($_POST['message'])){
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test@testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
答案 1 :(得分:0)
试试这个
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test@testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
$body= $_POST["message"]
if ($_SERVER["REQUEST_METHOD"] == "POST") {
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
当用户以
的形式提交消息时,会发送电子邮件至test@testemail.com