联系表单不发送发件人电子邮件 [英] contact form not sending senders email

查看:209
本文介绍了联系表单不发送发件人电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是一个常见的问题,但我似乎不明白为什么会发生这种情况。
我正在尝试处理表单,并将其发送到电子邮件。足够简单
这是它的PHP代码。当有人填写表单时,会显示除发件人电子邮件外的所有内容。它作为未知的发送者出来。有谁知道我如何解决它?
非常感谢任何需要超时观看的人。

i don't know if this is a common problem but i can't seem to understand why it is happening. I am trying to process a form and have it send the details to an email. Simple enough. Here is the PHP code for it. When someone fills the form up it shows everything except the senders email. It comes out as unknown sender. Does anyone know how i can fix it? Thanks a lot to anyone who takes time out to look at this.

<?php

if($_POST["submit"]) {
$recipient="emailx@gmail.com";
$subject="Form to email message";
$Name=$_POST["Name"];
$Phone=$_POST["Phone"]; 
$senderEmail=$_POST["senderEmail"];
$comments=$_POST["comments"];

$mailBody="Name: $Name\nPhone: $Phone\nEmail: $senderEmail\n\n$comments";

mail($recipient, $subject, $mailBody, "From: $Name <$comments>");

$thankYou="<p>Thank you! Your message has been sent.</p>";
}

?>


推荐答案

chris85 在评论中回答了问题:

chris85 answered the question in the comments:


来自 $ comments 不应该是 $ senderEmail

然而,这不是那么简单。您不能从电子邮件地址中选择任何,并期望它可以正常工作。如果您尝试欺骗地址,电子邮件客户端很可能会垃圾邮件。

However, it's not quite that simple. You can't just pick any from email address and expect it to work. The email client will most likely spam your emails if you try to spoof the from address.

每当您更改标题,你还需要更改回复到标题,在你的情况下,你应该把头作为您服务器上的电子邮件地址之一,只将回复标头更改为任何用户输入的内容。这样,您的邮件更有可能不会被垃圾邮件发送,因为它看起来并不像你想偷偷摸摸。

Whenever you change the From header you also need to change the reply-to header, in your case, You should probably put the From header as one of the email addresses on your server and only change the reply-to header to whatever the user in-putted. That way your messages are more likely to not be spammed because it doesn't look like you're trying to be sneaky.

另一种选择是使用一个简单的库照顾所有这一切。

Another option is to use a simple library to take care of all this for you.

这是一个非常简单的一个我写的: http://geneticcoder.blogspot.com/2014/08/wrapper-for-phps-mail-function.html

Here's a real simple one I wrote: http://geneticcoder.blogspot.com/2014/08/wrapper-for-phps-mail-function.html

这篇关于联系表单不发送发件人电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆