本文介绍了PHP电子邮件管道获取“至"字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试在PHP中使用电子邮件管道.

I am trying to use email piping with PHP.

除了无法获取收件人"字段之外,我都可以使用它.

I have it working except I can't get the 'To' field.

我正在使用以下PHP代码:

I am using the following PHP code:

#!/usr/bin/php -q
<?php

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd))
{
    $email .= fread($fd, 1024);

    $to1 = explode ("\nTo: ", $email);
    $to2 = explode ("\n", $to1[1]);
    $to = str_replace ('>', '', str_replace('<', '', $to2[0]));

}
fclose($fd);

mail('[email protected]','From my email pipe!','"' . $to . '"');

?>

如果我使用电子邮件地址(例如:[email protected])并将电子邮件发送到我的电子邮件地址,该电子邮件地址转发到我的PHP管道脚本(pipe.php),则我希望它能够找到谁电子邮件已发送到.

If I use a email address (for example: [email protected]) and send a email to my email address that is forwarded to my PHP piping script (pipe.php) I want it to be able to get who the email was sent to.

例如:[email protected]通过电子邮件将我的转发电子邮件发送到我的PHP管道脚本([email protected]),我希望它仅返回bob部分,而无需@ example.com

For Example:[email protected] emails my forwarding email that goes to my PHP piping script ([email protected]) I want it to return just the bob part only without the @example.com

现在发生的是,它返回了整个电子邮件地址,例如"[email protected]",而我希望它仅返回bob(不带任何谈话标记).

What happens now is that it returns the whole email address such as "[email protected]" and I want it to only return bob (without any talking marks).

我尝试使用此功能:

$to = $to.split("@");

但是我似乎收到一条错误消息:split()至少需要2个参数.这将发送给发送电子邮件的人.

but I seem to get an error that says: split() expects at least 2 parameters.That gets sent to the person who sent the email.

有人知道该怎么做,或者我可能做错了什么?

Does anyone know how to do this or know what I might be doing wrong?

这是我第一次在PHP中使用管道,所以如果我做错了事,请告诉我.

This is my first time using Piping in PHP, so if I am doing something wrong please let me know.

推荐答案

最终使用:

$to1 = explode ("\nTo: ", $email);
$to2 = explode ("\n", $to1[1]);
$to = str_replace ('>', '', str_replace('<', '', $to2[0]));
list($toa, $tob) = explode('@', $to);

然后将邮件更改为:

mail('[email protected]','From my email pipe!','"' . $toa . '"');

这篇关于PHP电子邮件管道获取“至"字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:12