简体   繁体   English

如何使用phpmailer跟踪通过smtp发送的电子邮件?

[英]How to track emails sent via smtp with phpmailer?

I'm using PHPMailer class correctly to send emails to multiple email addresses retrieved from the database. 我正确使用PHPMailer类将电子邮件发送到从数据库中检索到的多个电子邮件地址。

But should I store the emails sent and not sent with their reason in a database table? 但是,我应该将发送和不发送的电子邮件及其原因存储在数据库表中吗?

I would like to store sent emails in a DB table. 我想将发送的电子邮件存储在数据库表中。 Because every sent email can be confirmed by clicking the link on the email with a confirmation code. 因为可以通过单击电子邮件上带有确认码的链接来确认每个发送的电子邮件。 This response I would like to record. 我要记录此回复。

The response via the link is sent to the server with a unique confirmation code . 通过链接的响应将使用唯一的确认代码发送到服务器。 So the sent record in the table will be updated with a bool/tinyint attribute to record if details in email are confirmed. 因此,将使用bool / tinyint属性更新表中发送的记录,以记录是否确认电子邮件中的详细信息。

Could I allow the emails (sent via smtp with phpmailer) to be stored in sent folder within email account by following this: Sent mails with phpmailer don't go to "Sent" IMAP folder ? 我可以通过以下操作允许将电子邮件(通过phpmailer通过smtp发送)存储在电子邮件帐户内的已发送文件夹中: 使用phpmailer发送的邮件不要转到“已发送” IMAP文件夹 That way the email content is atleast accessible as I don't want to store those details in DB 这样,由于我不想将这些详细信息存储在数据库中,因此至少可以访问电子邮件内容

Is it better to record sent email sent in database? 记录在数据库中发送的已发送电子邮件是否更好?

For tracking bounced emails there are solutions: Track emails sent by SMTP with PHP 为了跟踪退回的电子邮件,有以下解决方案: 跟踪SMTP使用PHP发送的电子邮件

But what about the event where email is not sent due to an error? 但是,由于错误而没有发送电子邮件的情况该怎么办? Example when this happens: 发生这种情况的示例:

if(!$mail->Send())
{
   echo "Mailer Error: " . $mail->ErrorInfo;
}

Where should I store the error info for each email not sent? 对于未发送的每封电子邮件,我应该在哪里存储错误信息? Should this be recorded in DB table or put in log file? 应该将其记录在数据库表中还是放在日志文件中? DB seems more powerful for search and viewing.... DB在搜索和查看方面似乎更强大。

如果您使用的PHPMailer通过SMTP服务中继邮件像http://www.ultrasmtp.comhttp://sendgrid.com ,或http://jangosmtp.com -这些服务将跟踪成功/失败的交付和打开消息,并将此数据记录在他们自己的数据库中,您可以从中查看报告或搜索,还可以通过API或导出将这些信息提供给您。

1. You want to log the email outgoing and verify your users email by verification mail make following tables in your DB 1.您要记录发送的电子邮件,并通过验证邮件在数据库中建立以下表格来验证用户的电子邮件 在此处输入图片说明

  1. Now generate a random code in PHP and store it in users->verification_code 现在在PHP中生成一个随机代码,并将其存储在users->verification_code

  2. Send the same code into your user while inserting the email details in email_log . email_log插入电子邮件详细信息时, email_log用户发送相同的代码。

  3. When the users click's your verification link in his inbox cross check it with the one stored against his data in users table if its correct give him the access by changing verified to true. 当用户单击收件箱中的验证链接时,将其与在用户表中存储的数据相对应,以检查是否正确,如果正确,则通过将verify更改为true来授予他访问权限。

Hope this helps. 希望这可以帮助。

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

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