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

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要