简体   繁体   English

PHPMailer 使用 Sendgrid,自定义每个 email 但只发送一个 email

[英]PHPMailer using Sendgrid, customizing each email but sending just one email

Our main programmer died from covid.我们的主要程序员死于新冠病毒。 He had built a program in his code using Swiftmailer, which is no longer active.他使用 Swiftmailer 在他的代码中构建了一个程序,该程序不再处于活动状态。

I am going to reprogram it all using PHPmailer.我将使用 PHPmailer 对其进行重新编程。

But I don't know how to customize each email with their first name, username in our website and their custom info.但我不知道如何使用他们的名字、我们网站上的用户名和他们的自定义信息来自定义每个 email。

In the PHP for swiftmailer, he did it like this:在 swiftmailer 的 PHP 中,他是这样做的:

$hdr = new SmtpApiHeader();
// Set all of the above variables
$hdr->addTo($toList);
$hdr->addSubVal('~USERNAME~', $usernameList);
$hdr->addSubVal('~FirstName~', $firstnameList);
$hdr->addSubVal('~code~', $codeList);

~code~ was a merge field to replace a security code when it sent an email to them, like if they changed their password, and they needed to get a code to authenticate it was from them. ~code~ 是一个合并字段,当它向他们发送 email 时替换安全代码,就像他们更改了密码一样,他们需要获取代码来验证来自他们的身份。 or update their profile.或更新他们的个人资料。

so those are where he added their personalizations, those were arrays.所以这些是他添加个性化的地方,那些是 arrays。

$toList // this would be an array of every email. then it matched the position of the other arrays for their personal info, to put in each email.

He built these as the function to send one email, or many, depending on what the email is for.他将这些构建为 function 以发送一个 email 或多个,具体取决于 email 的用途。 All based upon subscribers who have opted in to get transactional emails from the system.所有这些都基于选择从系统获取交易电子邮件的订阅者。

So how do we do this with PHP Mailer?那么我们如何使用 PHP Mailer 做到这一点呢? I have been reading since last night, everything I could find and I cannot see how to do it.从昨晚开始我就一直在阅读,我能找到的所有东西,但我不知道该怎么做。

can someone point me to a place online with the right documentation?有人可以用正确的文档将我指向一个在线的地方吗? Most of what I read, none of it touched on it.我读过的大部分内容,都没有涉及到它。

I feel like I've been spinning my wheels.我觉得我一直在转动我的轮子。

Thanks for any pointers.感谢您的任何指示。

-Rich -富有的

You can set all the message parameters through equivalent properties in PHPMailer, such as From , FromName , Subject (and many more, see the docs ), but PHPMailer does not have built-in templating.您可以通过 PHPMailer 中的等效属性设置所有消息参数,例如FromFromNameSubject (还有更多,请参阅文档),但 PHPMailer 没有内置模板。 There are many ways to do that, and many packages that can help you do it (Smarty, Twig, etc), so I recommend you use them.有很多方法可以做到这一点,并且有很多包可以帮助你做到这一点(Smarty、Twig 等),所以我建议你使用它们。

For sending to lists, look at the mailing list example provided with PHPMailer .要发送到列表,请查看PHPMailer 提供的邮件列表示例

Alternatively, while SwiftMailer itself is no longer supported separately, that only happened because it became Symfony's mail component .或者,虽然 SwiftMailer 本身不再单独支持,但这只是因为它成为了Symfony 的邮件组件 I've not looked at it, but I strongly suspect that it will be largely unchanged, so you may find it easier to use that.我没有看过它,但我强烈怀疑它在很大程度上不会改变,所以你可能会发现它更容易使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM