问题描述
我们一直在使用PEAR Mail,但是由于我想转换为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.
我遇到的问题是,我们现有的sendEmail方法期望电子邮件地址为字符串,例如
The problem I have run into is that our existing sendEmail method expects email addresses as a string like
display name <[email protected]>, another display name <[email protected]>
PHPmailer依次获取每个地址,并将地址和显示名称作为单独的参数传递,例如:
Whereas PHPmailer takes each address in turn and passes the address and the display name as separate parameters eg:
$mail->addAddress('[email protected]','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
推荐答案
我一直想解决这个问题已有一段时间,因为它已经坐在PHPMailer问题队列中了两年了,所以我终于做到了关于它的东西.
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.
在GitHub上的HEAD 中,或者在PHPMailer 5.2.11发布时,您可以执行以下操作:
In HEAD on GitHub, or PHPMailer 5.2.11 when it's released, you can do this:
$a = 'Joe User <[email protected]>, Jill User <[email protected]>';
foreach ($mail->parseAddresses($a) as $address) {
$mail->addAddress($address['address'], $address['name']);
}
这篇关于从名称< [email protected]>转换地址到phpmailer格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!