PHP email Piping get 'to' field

拟墨画扇 提交于 2019-12-24 09:04:06

问题


I am trying to use email piping with PHP.

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

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@example.com','From my email pipe!','"' . $to . '"');

?>

If I use a email address (for example: john@smith.com) 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.

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

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

I have tried using this:

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

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?

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


回答1:


Ended up using:

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

then changed the mail to:

mail('email@example.com','From my email pipe!','"' . $toa . '"');


来源:https://stackoverflow.com/questions/13548859/php-email-piping-get-to-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!