我正在将收到的电子邮件传送到 handler.php。我可以成功地通过管道传输它并且它正在工作,但是当它从邮件标题中取出变量时,例如“主题”或“收件人”或“邮件正文”,我遇到了一些问题。这是我从这里得到的代码
这是代码:
<?php
//Assumes $email contains the contents of the e-mail
//When the script is done, $subject, $to, $message, and $from all contain appropriate values
//Parse "subject"
$subject1 = explode ("\nSubject: ", $email);
$subject2 = explode ("\n", $subject1[1]);
$subject = $subject2[0];
//Parse "to"
$to1 = explode ("\nTo: ", $email);
$to2 = explode ("\n", $to1[1]);
$to = str_replace ('>', '', str_replace('<', '', $to2[0]));
$message1 = explode ("\n\n", $email);
$start = count ($message1) - 3;
if ($start < 1)
{
$start = 1;
}
//Parse "message"
$message2 = explode ("\n\n", $message1[$start]);
$message = $message2[0];
//Parse "from"
$from1 = explode ("\nFrom: ", $email);
$from2 = explode ("\n", $from1[1]);
if(strpos ($from2[0], '<') !== false)
{
$from3 = explode ('<', $from2[0]);
$from4 = explode ('>', $from3[1]);
$from = $from4[0];
}
else
{
$from = $from2[0];
}
?>
对于 Gmail 电子邮件,它可以很好地获取主题、发件人、收件人和邮件正文,但它不适用于来自 Yahoo 的传入电子邮件。
是否有任何与所有著名电子邮件服务提供商兼容的通用 php 类?如果有人从 RoundCube 或其他电子邮件发件人发送电子邮件怎么办?我怎样才能成功检测到变量?
谢谢!