douyi1966 2015-05-21 10:58
浏览 45
已采纳

将地址从名称<address@domain.tld>转换为phpmailer格式

We have been using PEAR Mail but as this hasn't been maintained for a while I am wanting to convert to PHPmailer instead. We have an existing email class which wraps the actual mailer so conversion isn't looking too difficult so far.

The problem I have run into is that our existing sendEmail method expects email addresses as a string like

 display name <address@domain.tld>, another display name <address2@domain.tld>

Whereas PHPmailer takes each address in turn and passes the address and the display name as separate parameters eg:

$mail->addAddress('address@domain.tld','display name');

I need a routine to parse the old style addresses and separate out the addresses from the display names; I can write this but I don't want to re-invent the wheel and I don't think I can be the first person who has come across this issue (though my searching has failed to find an existing solution).

Can anyone point me at an existing solution to this?

Edited because I had reversed the display name details

  • 写回答

3条回答 默认 最新

  • dongmu5246 2015-05-21 15:17
    关注

    I've been meaning to get around to this for a while, as it's been sitting in the PHPMailer issues queue for a couple of years, so I finally did something about it.

    In HEAD on GitHub, or PHPMailer 5.2.11 when it's released, you can do this:

    $a = 'Joe User <joe@example.com>, Jill User <jill@example.net>';
    foreach ($mail->parseAddresses($a) as $address) {
        $mail->addAddress($address['address'], $address['name']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?