这是一个相对简单的问题,可能没有解决办法。
是否可以将消息设置为:头并在中发送电子邮件?注意,消息到:不同于信封到:标题。后者实际上决定电子邮件的路由位置,而前者只确定它在收件人的电子邮件程序中显示的内容。
背景:我正在为自己设置一个小的一次性电子邮件服务,所以我接收带有PHP脚本的电子邮件,修改一些标题,并将其重新发送到我的真实电子邮件地址。我希望原始收件人的电子邮件地址(即一次性电子邮件地址)在收到邮件时仍然显示在我的真实邮箱中(用于客户端过滤规则等)。
这个是可能的吗?我已经能够修改每一种类型的标题,但这一个让我卡住了。
发布于 2012-02-18 22:48:22
谢谢大家的帮助!我找到了一个很好的解决方案,所以我想和大家分享一下。
最后,我只是扩展了CodeIgniter的电子邮件类,将设置为头(到目前为止,我开始称它为虚荣心标头,因为它的外观和内容都是虚空的),并通过SMTP发送。如果您希望看到我所做的简单示例,请使用自己的MY_Email.php文件扩展电子邮件类(请参阅“用户指南”中关于扩展本地图书馆的部分),并从电子邮件类复制_build_headers()函数。
/**
* Build final headers
*
* @access protected
* @param string
* @return string
*/
protected function _build_headers()
{
$this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
$this->_set_header('X-Mailer', $this->useragent);
$this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
$this->_set_header('Message-ID', $this->_get_message_id());
$this->_set_header('Mime-Version', '1.0');
}然后在Mime行的正下方添加您自己的标题,如下所示:
$this->_set_header('To', 'person@example.com');然后,只需发送一个定期电子邮件到您自己的电子邮件地址之一。您会注意到,即使电子邮件到达您的地址,它似乎是以person@example.com为地址。
轰隆隆。
如果您真的想使用我创建的完整MY_Email.php文件向您自己的CodeIgniter项目看这个要点添加一个“虚荣心”选项。
发布于 2012-02-18 05:30:57
这里我用的是这样的东西:
$message = 'Your Message';
$subject = 'Your Subject';
$headers = 'Your headers';
$to = 'Address to send to';
$headers = 'Reply-To: Address'; //Perhaps you are looking for this?
mail($to,$subject,$message,$headers);希望这对你有用!
编辑:对不起误解了你的问题。
发布于 2012-02-18 05:41:17
在用PHP发送电子邮件时,我总是使用一个使用STMP的自定义函数,在该函数中,它使用以下标题来设置我认为您试图设置的名称:
"To: $nameto <$emailto>"其中$emailto是您发送给的实际电子邮件,而$nameto是您希望它显示的对象。
下面是我使用的函数,如果您需要更改您可以修改的任何其他标头,它们将接近函数的末尾:
/*
Desc: Used to send emails from stmp server. Make sure to have the config variables set (at the top of function). Stores logs in array, you'll need to modify the function to actually use the array though.
Params:
String $from - Email address that the email is from. Ex. "john.smith@example.com"
String $namefrom - Name to go along with the email address. Ex. "John Smith"
String $to - Email address of the recipient of the email. Ex, "jane.doe@example.com"
String $nameto - Name to go along with the email address. Ex. "Jane Doe"
String $subject - Email subject.
String $message - Main contents of email.
Return: true on success false on failure.
*/
function amail($from, $namefrom, $to, $nameto, $subject, $message)
{
$smtpServer = "";
$port = 0;
$username = "";
$password = "";
$timeout = 30;
$localhost = "127.0.0.1";
$newLine = "\r\n";
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout) or die('Could not connect.');
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect)){
return false;
} else {
$logArray['connection'] = "Connected: $smtpResponse";
}
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
$headers .= "Subject: $subject" . $newLine;
fputs($smtpConnect, "$headers\n\n$message\n".$newLine.".".$newLine);
$smtpResponse = fgets($smtpConnect, 1024);
$logArray['data2response'] = "$smtpResponse";
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
return true;
}https://stackoverflow.com/questions/9338769
复制相似问题