dongpo1599 2012-12-03 14:00
浏览 16
已采纳

从电子邮件地址获取电子邮件解析器

I am using this absolute amazing piece of code: https://github.com/plancake/official-library-php-email-parser/blob/master/PlancakeEmailParser.php

But the one thing it is missing is the ability to get the From email address.

I have simple added:

public function getFromEmail()
{
    if (!isset($this->rawFields['from']))
    {
        return false;
    }

    return $this->rawFields['from'];
}

But how would I get only the email address part at the moment it returns: John Smith<john@gmail.com>?

Also I would need this to work if the From address was only john@gmail.com?

Thanks to the answers this was the finished code:

public function getFromEmail()
{
    $email = trim($this->rawFields['from']);

    if(substr($email, -1) == '>'){
        $fromarr = explode("<",$email);
        $mailarr1 = explode(">",$fromarr[1]);
        $email = $mailarr1[0];
    }

    return $email;
}
  • 写回答

2条回答 默认 最新

  • duan0514324 2012-12-03 14:05
    关注
    $mailid='John Smith<john@gmail.com>';
    $mailarr=explode("<",$mailid);
    $mailarr1=explode(">",$mailarr[1]);
    $just_emailid=$mailarr1[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题