php PHP邮件功能'发件人'地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10741165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:55:29  来源:igfitidea点击:

PHP mail function 'from' address

emailphp

提问by The Crazy Chimp

I'm not even sure this is possible, however what I'm trying to do is as follows. I have an HTML form that generates and email using a PHPscript. What I want is to recieve emails from this form to [email protected], then I want the fromaddress to appear as one of the fields in the form.

我什至不确定这是可能的,但是我正在尝试做的如下。我有一个 HTML 表单,它使用PHP脚本生成和发送电子邮件。我想要的是从这个表单接收电子邮件到[email protected],然后我希望from地址显示为表单中的字段之一。

I have had a look around and found some useful information on this site. I'm not sure whether sendmail_fromcan be used in this situation, or if it does what I'm asking.

我环顾四周,在这个网站上找到了一些有用的信息。我不确定是否sendmail_from可以在这种情况下使用,或者它是否符合我的要求。

Is this possible, if so how?

这是可能的,如果可以,如何?

回答by Ricardo Souza

See this page on the same site (example 2): http://www.w3schools.com/php/func_mail_mail.asp

在同一站点上查看此页面(示例 2):http: //www.w3schools.com/php/func_mail_mail.asp

You will have to set the headers of the message to include the From and other stuff like CC or BCC:

您必须设置消息的标题以包含发件人和其他内容,例如抄送或密件抄送:

<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]\r\n";

mail($to,$subject,$txt,$headers);
?>

Note that you have to separate the headers with a newline sequence "\r\n".

请注意,您必须使用换行序列分隔标题"\r\n"

回答by SteveLacy

For a php mail script I have used this for contact forms:

对于 php 邮件脚本,我已将其用于联系表单:

$from = $_POST["from"];  //posted from the form.

mail("[email protected]", $subject, $message, "From:" . $from);

I have not used a sendmail_from in my php before, only a simple variable.

我之前没有在我的 php 中使用过 sendmail_from,只有一个简单的变量。

I hope this helps!

我希望这有帮助!

回答by DickieBoy

Any reason you cant do it in the email headers?

你有什么理由不能在电子邮件标题中做到这一点?

$to      = '[email protected]';
$subject = 'my subject';
$message = 'hello';
$headers = 'From: '.$email_from_form. "\r\n";

mail($to, $subject, $message, $headers);