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条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?