如何通过从数据库中获取对象来创建电子邮件通讯?

发布于 2024-08-30 21:56:36 字数 217 浏览 7 评论 0原文

好吧,我正在尝试创建一个新闻通讯,它将向数据库中的用户发送电子邮件。时事通讯本身将从数据库中提取“事件”和其他活动。获取该列表并将其放入电子邮件中的最佳方式是什么?我正在考虑将它们放入 html 页面,然后发送 html 电子邮件,但并非所有电子邮件都支持 html(例如学校电子邮件)。你们会推荐什么?你能给我推荐一些好的资源吗?

另外,这是一个学校项目,所以我不能使用任何开源类型的东西,不幸的是:(

Well, I'm trying to create a newsletter, that will send emails to users in a database. The newsletter itself would draw "events" and other activities from a database. Whats the best way to take that list, and put them in an email? I was thinking about putting them into an html page, then sending an html email, but not all emails support html(like school email). What would your guys recommend? Could you point me to some good resources?

Also, this is for a school project, so I cant use any open source type stuff, unfortunately :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2024-09-06 21:56:36

您的假设是正确的,即如果您要创建 html 新闻通讯,则还必须为不支持 html 或要求仅以文本形式发送电子邮件的客户制作基于文本的版本。您需要确保您的代码将两个版本发送给收件人。您还可以询问收件人的偏好并向他们发送他们请求的特定版本。

对于 html 电子邮件,强烈建议阅读 CampaignMonitor 的以下两篇文章(他们专门研究电子邮件营销软件):

请注意,我假设您正在寻求有关电子邮件 html 实际构建的帮助,而不是寻求创建和发送新闻通讯所需的代码。

祝你的项目好运。

====更新====

所以看来您在开发这个项目时确实需要帮助。由于这是一项家庭作业,我将提供一些一般性建议,引导您走向正确的方向并开始该项目。然后,如果您的代码有任何具体问题,您可以在 Stackoverflow 上询问。

这里实际上需要做两件事:

  1. 在 PHP 中,动态构造一个变量,其中包含需要发送的电子邮件的 html 或文本版本。
  2. 循环浏览您的联系人列表并通过电子邮件发送该变量的内容。

发送电子邮件

我将从发送电子邮件部分开始,因为下面提供的链接还向您展示了如何构建消息。另外,在您的评论中您说您已经知道如何从数据库构建 html。以下链接向您展示了两种发送电子邮件的方法。您可以使用 PHP 自带的 Mail 功能,也可以下载 PEAR_Mail 包。如果您被允许使用其他库并想要发送 html 电子邮件,我建议您使用 PEAR_Mail,因为如果您想同时发送 html 和文本版本的电子邮件,它会使事情变得更加容易。

注意:要发送电子邮件,您将需要使用某种邮件服务器。如果您使用的是 Windows,则可以安装 IIS 附带的 SMTP 服务,也可以使用外部 smtp 服务(例如 google)来发送电子邮件。

构造电子邮件

这里的复杂性取决于您是否只需要纯文本电子邮件或 html。无论哪种情况,您都需要从数据库中读取事件数据并将其添加到您要发送的消息中。

一些 Seudocode:

Loop through datarows
   message = DataRow[EventDate] + " " + DataRow[EventName] + "\n"

Loop through recipients 
   mail message

希望这能给您一个开始。我建议首先让 php 发送静态 html 或文本的电子邮件。一旦代码可以运行,您就可以开始添加从数据库读取事件信息并将其发送出去的功能。

希望这有帮助。

You are correct in your assumption that if you are creating html newsletters, you will also have to do a text based version for clients that don't support html or ones that ask to have e-mail be sent only in text. You will need to make sure your code sends both versions to recipients. You could also ask the recipients for their preference and send them the specific version that they requested.

For html e-mail it is highly recommended to read the following two articles by CampaignMonitor (they specialize in e-mail marketing sofware):

Note that I am assuming you are asking for help with the actual construction of the html for the email not the code needed to create and send the newsletter.

Good luck with your project.

==== UPDATE ====

So it seems that you actually need help in developing this project. Since this is a homework, I will provide some general advice that should steer you in the correct direction and get you started on the project. Then, if you have any specific problems with your code, you can ask about them on Stackoverflow.

There is really two things that need to be done here:

  1. In PHP, dynamically contruct a variable that contains the html or text versions of the e-mail that needs to be sent.
  2. Loop through your contact list and e-mail the contents of that variable.

Sending E-mail

I will start with the sending e-mail portion, because the links provide bellow also show you how to construct the message. Also, in your comment you said you already know how to contruct an html from a database. The following links show you two ways to send e-mail. You can either use the Mail function that comes with PHP or download the PEAR_Mail package. If you are allowed to use additional libraries and want to send html e-mail, I would recommend using the PEAR_Mail, because it makes things much easier if you want to send a both an html and text version of an e-mail together.

Note: To send an e-mail you will need to use some sort of mail server. If you are using Windows, you can install the SMTP service that comes with IIS or you can use an external smtp service such as google to send your e-mails.

Construct E-mail

The complexity here will depend on whether you just want a plain text e-mail or html. For either case you will need to read the event data from your database and add it to the message that you want to send.

Some Seudocode:

Loop through datarows
   message = DataRow[EventDate] + " " + DataRow[EventName] + "\n"

Loop through recipients 
   mail message

Hopefully this gives you a start. I would recommend getting php to send out an e-mail of a static html or text first. Once you have that code working you can start working on adding the functionality of reading event info from a database and sending it out.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文