[英]Contact form doesnt send complete email
I managed to make my contact form work but somehow i cant make it send the message structured how i want... 我设法使我的联系表格工作,但不知何故,我不能让它发送消息结构我想要...
My code is this: 我的代码是这样的:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$messagesubject = $_POST['subject'];
$text = $_POST['text'];
$to = "name@email.com";
$subject = 'Message from a site visitor '.$name;
$content = 'Name: '.$name."\r\n";
$content .= 'E-mail: '.$email."\r\n";
$content .= 'Subject: '.$messagesubject."\r\n";
$content .= 'Message: '.$text."\r\n";
$send_contact=mail($to,$subject,$content);
if($send_contact){
echo "Thank you!";
}
else {
echo "ERROR";
}
?>
I receive a mail but on the senders address (From) is written my e-mail address from the hosting server. 我收到一封邮件,但发件人地址(From)是从托管服务器写的我的电子邮件地址。 If i add $headers ( i created the headers like this: " $headers = 'From: '.$field_email."\\r\\n"; ") in the mail() than i dont receive any mail...
如果我添加$ headers(我创建了这样的标题:“$ headers ='From:'。$ field_email。”\\ r \\ n“;”)在mail()中,而不是我没有收到任何邮件...
Please help... 请帮忙...
(*i reedited my post) (*我reedited我的帖子)
You have three errors (and one bonus mistake): 你有三个错误(和一个红利错误):
You put the body of the message in a variable called $message
but use a variable called $text
in your mail()
function. 您将消息正文放在名为
$message
的变量中,但在mail()
函数中使用名为$text
的变量。
You use the wrong variable for your headers. 您为标题使用了错误的变量。 You use
$email
it should be $headers
你使用
$email
它应该是$headers
Plus it appears you have the variables in your mail()
function out of order. 此外,您的
mail()
函数中的变量似乎无序。 Headers go after message body. 标题追踪消息体。
You write a variable called $formcontent
but never use it. 你编写了一个名为
$formcontent
的变量,但从不使用它。 It is redundant with $message
anyway. 无论如何,它与
$message
是多余的。
$send_contact=mail($to,$subject,$message,$headers);
Try This 尝试这个
<?php
error_reporting(0);
if(isset($_POST['submit_button']))
{
$to = 'name@gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$subject = $_POST['subject'];
$message.="Name : $name \n \n";
$message.="Email : $email \n \n";
$message.="Message : $msg \n \n";
$headers = "From: ".$_POST['email']." (My Email Form )";
if(mail($to, $subject, $message, $headers))
{
echo "Thank you!";
}
else {
echo "ERROR";
}
}
?>
<form id="contact-form" method="POST">
<input name="name" type="text" class="form-control" placeholder="Name" required>
<input name="email" type="email" class="form-control" placeholder="Email" required>
<input name="subject" type="text" class="form-control" placeholder="Subject" required>
<textarea name="msg" class="form-control" placeholder="Message" rows="5" cols="30" required></textarea>
<input type="submit" name="submit_button" value="send"/>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.