简体   繁体   English

网站联系表单提交空白电子邮件

[英]Website contact form submits blank emails

I'm having an issue with the contact form on my website! 我的网站上的联系表格有问题! I've tried searching online for answers but I'm new to this website building and would appreciate a simple answer, if possible. 我尝试在线搜索答案,但我是这个网站建设的新手,如果可能的话,我会很感激一个简单的答案。 I guess the coding is wrong somewhere but I really wouldn't know where! 我猜编码在某处错了,但我真的不知道在哪里!

The issue - I receive the email after pressing submit but in my inbox it only displays a subject line and does not show the message, email or the name of the person its from. 问题 - 我按下提交后收到电子邮件,但在我的收件箱中,它只显示主题行,不显示消息,电子邮件或其来自的人的姓名。

Please help! 请帮忙!


Here is the HTML code: 这是HTML代码:

<form action="result.php" method="post">

<input name="Name" class="" type="text" value="Name (Required)" onfocus="if(this.value == 'Name (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Name (Required)'; }" />

<input name="Email" class="" type="text" value="Email (Required)" onfocus="if(this.value == 'Email (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Email (Required)'; }" />

<input name="Subject" class="" type="text" value="Subject" onfocus="if(this.value == 'Subject') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Subject'; }" />

<textarea name="Detail" cols="" rows="" onfocus="if(this.value == 'Describe your project in detail...') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Describe your project in detail...'; }">Describe your project in detail...</textarea>

<input type="submit" name="submit" action="submit" value="submit"  class="submitbtn" />
<input type="reset" name="reset" action="reset" value="reset" class="resetbtn" />
</form>

and the PHP code: 和PHP代码:

<?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$subject = $_POST['Subject'];
$detail = $_POST['Detail'];
$to = "info@philippamichael.com";
$subject = "Contact Form Submission";
mail ($to, $subject, $detail, "From" . $name);
echo "Thank You. Your Message has been sent.";

?>

Yo don't seem to be using $email anywhere, and your from header does not have the right format. 哟似乎没有在任何地方使用$email ,而你的标题没有正确的格式。 Maybe something like this: 也许是这样的:

<?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$subject = $_POST['Subject'];
$detail = $_POST['Detail'];

$to = "info@philippamichael.com";
$subject = "Contact Form Submission";
$message = $detail . "\n\nFrom Name: {$name}";
$message .= "\nFrom Address: {$email}";

mail ($to, $subject, $message , "From: info@philippamichael.com");

echo "Thank You. Your Message has been sent.";

Notice that I removed your From header entirely, since you don't want to send from an arbitrary address. 请注意,我完全删除了您的From标头,因为您不想从任意地址发送。 It's better to use a no-reply address or the like, from your own domain name, and simply include the contact information in the body of the e-mail. 最好使用您自己的域名中的无回复地址等,只需在电子邮件正文中包含联系信息即可。

Check the mail function from: http://www.php.net/manual/en/function.mail.php 检查邮件功能: http//www.php.net/manual/en/function.mail.php

 bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

The 4th parameter is additional_headers, so your format may be wrong. 第四个参数是additional_headers,因此您的格式可能有误。 try: 尝试:

mail ($to, $subject, $detail, "From: " . $name);

Your headers are wrong... Use this syntax. 您的标头错误...使用此语法。

$to = "info@philippamichael.com";
$subject = "Contact Form Submission";
$message = $detail;
$headers = "From: ".$name;
$headers .= "\r\nMIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\r\n";
mail($to,$subject,$message,$headers);

This should work. 这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM