使用 php 脚本跟踪 php 电子邮件?

发布于 11-15 18:02 字数 501 浏览 6 评论 0 原文

我正在使用 php mail() 函数发送电子邮件通讯。

我必须跟踪简讯电子邮件状态。

状态为
1. 发送数量
2. 已交付数量。
3. 交货日期。
4. 总读取次数
5. 独特的阅读次数
6. 读取日期。
7. 退回邮件数量。
8. 点击电子邮件中链接的用户总数。
9. 单击电子邮件中链接的唯一用户数。

从上述状态我可以跟踪以下内容:
1. 已发送。 // 这是从编码发送时进行跟踪的。
8. 点击电子邮件中链接的总数。 // 这是通过在 url 中添加附加参数来跟踪的。
9. 单击电子邮件中链接的唯一数量。 // 这是通过在 url 中添加附加参数来跟踪的。

如何跟踪mail()函数发送的电子邮件的其他状态?
我必须从同一服务器发送和跟踪电子邮件。

I am sending email newsletters using php mail() function.

I have to track the newsletter emails status.

The status would be

1. Num.Of Sent.
2. Num.Of Delivered.
3. Delivered date.
4. Total Num.Of Read.
5. Unique Num.Of Read.
6. Read date.
7. Num.Of Bounced.
8. Total Num.Of users clicked the links in the email.
9. Unique Num.Of users clicked the links in the email.

From the above status i could track the following:

1. Is Sent. // This is tracked as it is sent from coding.
8. Total Num.Of clicked the links in the email. // This is tracked by adding additional parameters in url.
9. Unique Num.Of clicked the links in the email. // This is tracked by adding additional parameters in url.

How to track the other status of the emails sent from mail() function?

I have to send and track emails from same server.

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

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

发布评论

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

评论(7

浅语花开 2024-11-22 18:02:54

您无法通过 mail() 函数直接跟踪其他状态。从技术上讲,“已发送”仅告诉您邮件已成功传递到服务器的出站邮件队列 - 您实际上无法判断它是否离开了服务器。

1、.您需要检查邮件服务器日志以准确了解电子邮件离开服务器的时间。

2,3。投递次数和投递日期 - 同样,您需要检查邮件服务器日志以查看邮件何时(成功)移交给第三方邮件服务器。然而,这些统计数据的可靠性取决于您对已发送的定义(发送到最终用户邮箱?发送到他们的电子邮件客户端?)。

4,5,6。阅读总数、阅读唯一数、阅读日期。你无法准确追踪这一点。但是,如果您发送 HTML 电子邮件,您可以将图像嵌入到电子邮件中,其中图像的来源是您的网络服务器。如果每个图像 URL 对于您发送电子邮件的人都有一个唯一的标识符,那么您可以从服务器日志中跟踪此信息(如果该 url 是返回图像的 php 脚本,则可以通过 php 进行跟踪)。然而,这依赖于最终用户允许从外部网络服务器加载图像(例如,Outlook 和 gmail 默认情况下关闭此功能)。

7、.如果您将发件人地址发送为服务器上的脚本,它可以解析退回邮件并确定退回的数量。或者,您可以将发件人地址设为您手动进入并检查的邮箱。

8, 9. 电子邮件中的每个链接都需要是指向您的网络服务器上的 URL 的链接。该 URL 可以是一个脚本,用于跟踪谁点击了(通过使用查询变量)以及他们想要查看的内容(另一个查询变量),然后将它们重定向(php 中的标头函数)到您希望它们结束的位置。

You can't directly track the other status from the mail() function. Technically Is Sent only tells you that the mail was passed over to the server's outbound mail queue successfully - you can't actually tell if it left your server.

1,. You will need to check your mail server logs to see exactly when the email left the server.

2,3. Num of delivered and delivered date - again you would need to check your mail server logs to see when the mail was handed over (successfully) to a third party mail server. However it would depend on your definition of delivered (into the end-users mailbox? Into their email client?) as to how reliable these stats would be.

4,5,6. Total number read, unique number read, read date. You can't accurately track this. However if you sent HTML email you could embed an image into the email whereby the source of the image was your webserver. If each image URL had a unique identifier for the person you sent the email to then you could track this from your server logs (or via php if the url was a php script that returned an image). However this relies on the end user allowing the loading of images from external webservers (Outlook and gmail for example have this turned off by default).

7,. If you sent the from address to be a script on your server it could parse the bounce message and determine how many bounced. Alternatively you can just have the from address be a mailbox that you go into and check manually.

8, 9. Each link in the email would need to be a link to a url on your webserver. That URL could be a script that would track who clicked (by the use of a query variable) and what they want to see (another query variable) and then redirect them (header function in php) to where you want them to end up.

沧笙踏歌 2024-11-22 18:02:54

要获得所有这些统计信息,您将必须使用不同的系统:

检查发送的号码

邮件功能的返回代码并不可靠,它仅告诉您系统将开始尝试发送邮件。您必须使用专门的 PHP 类,该类通过 SMTP 本身进行通信或解析系统邮件日志。但请记住这个数字几乎毫无意义,这导致了下一点...

检查已发送的数字

即使您自己开始解析邮件日志或使用专门的 PHP 类通过 SMTP 发送,您也只能检查第一个服务器在您将电子邮件传递到的链中。例如,在一家大公司中,邮件可能会传递到中央邮件服务器,您可以检查该服务器。然后发送到公司的另一个内部邮件服务器,该服务器拒绝邮件。你永远不会知道。更不用说垃圾邮件过滤器了。因此,无法判断邮件是否已送达 - 直到下一点...

检查阅读次数

更正式地说,您必须说“检查打开的电子邮件数量”。为此,您可以将具有唯一 URL 的图像添加到 HTML 邮件中,例如 http:// /mywebsite.com/images/IDOFRECIPIENT/IDOFMAILING/logo.jpg - 当请求 URL 时,您知道相应的收件人打开了邮件。缺点:如果收件人阻止加载外部内容,您将无能为力,您将永远不会知道他的阅读情况。

链接点击次数

这很简单:将邮件中的所有链接替换为您自己域中的链接。当访问这些链接时,会出现一个计数器,并将访问者转发到真实站点。请注意:如果 HTML 电子邮件中的链接文本包含域名称,但您链接到另一个域,则大多数电子邮件客户端会认为它是垃圾邮件。例如,

www.citibank.com

is bad.

弹跳

那是很难的。在您的电子邮件中指定“发件人”标头。这是电子邮件被退回的地址。您可以使用“发件人”标头之外的其他地址,这意味着当收件人点击“回复”按钮时,他可以将电子邮件发送到 [电子邮件受保护],但如果退回,电子邮件将转到 [电子邮件受保护]

诀窍是创建退回地址作为整个域的包罗万象 - 因此每封发送到“"="">[电子邮件受保护]" 应转到同一个收件箱。在电子邮件地址中,您保存收件人和邮件的 ID:bounces-[recipientid]-[mailingid]@newsletter.yourdomain.com。收件人地址是退回时唯一可靠的数据,其他所有数据都可能被收件人的邮件服务器删除。

然后只需编写一个 PHP 脚本,通过 POP3 获取邮件并检查发件人。

希望我能帮助你!

To get all these stats, you will have to use different systems:

Checking for number sent

The return code of the mail function is not reliable, it only tells you that the system will start to try to send the mail. You would have to use a specialised PHP class that communicates via SMTP itself or parse the systems mail logs. But remember this number is near meaningless, which leads to the next point...

Checking for number delivered

Even if you would start to parse the mail logs or use a specialised PHP class to send via SMTP yourself, you could only check the first server in the chain you pass the email to. For example, in a big company the mail might be passed to a central mail server, which you can check. Then it is sent to another internal mail server of the company, which refuses the mail. You'll never know. Not even speaking of spam filters. So, there is no way to tell whether a mail was delivered - until the next point...

Checking number of reads

More formally, you'd have to say "checking number of emails opened". For that, you add an image with an unique URL to your HTML mail, for example http://mywebsite.com/images/IDOFRECIPIENT/IDOFMAILING/logo.jpg - when the URL is requested, you know the corresponding recipient opened the mailing. Downside: if the recipient blocks loading of external contents, there is nothing you can do about it, you'll never know about his reading.

Number of clicks on links

That one is simple: replace all the links in the mail with links on your own domain. When these links are visited, a counter is raised and the visitor is forwarded to the real site. Beware: if the link text in your HTML email contains the name of a domain, but you link to another domain, most email clients will believe it is spam. So for example,

www.citibank.com

is bad.

Bounces

Thats a hard one. Specifiy a "Sender" Header in your email. This is the address the email is bounced to. You can use another address than the "From" Header, which means that when a recipient hits the "Reply" button, he can send an email to [email protected], but if it bounces, the email goes to [email protected].

The trick is to create the bouncing addresses as a catch-all for the whole domain - so every email sent to "[email protected]" should go to the same inbox. Inside the email adress, you save the id of the recipient and of the mailing: bounces-[recipientid]-[mailingid]@newsletter.yourdomain.com. The recipient address is the only reliable data when bouncing, everything else might be removed by the mailserver of the recipient.

Then just code a PHP script that fetches the mails via POP3 and checks the sender.

Hope I could help you!

℉絮湮 2024-11-22 18:02:54

对于发送的数量,您可以使用基本包装器:

class Mailer
{
    /**
     * Events
     *
     * @var array
     */
    protected $_events = array();

    /**
     * Number of successful emails
     *
     * @var int
     */ 
    protected $_numFailures = 0;

    /**
     * Number of failed emails
     *
     * @var int
     */ 
    protected $_numSuccesses = 0;

    /**
     * Send email using PHP mail() function
     * 
     * @param string $to Send to email address
     * @param string $subject Email subject
     * @param string $message Email message
     * @param string $additionalHeaders Optional. Additional headers
     * @param string $additionalParams Optional. Additional params
     * @return Mailer
     */
    public function mail($to, $subject, $message, $additionalHeaders = '', $additionalParams = '')
    {
        $result = mail($to, $subject, $message, $additionalHeaders, $additionalParams);

        if ($result) {
            $this->_numSuccesses++;
        } else {
            $this->_numFailures++;
        }

        if (isset($this->_events['mail'])) {
            foreach ($this->_events['mail'] as $event) {
                $event($result, $to, $subject, $message);
            }
        }

        return $this;
    }

    /**
     * Get total number of emails sent
     *
     * @return int
     */
    public function count()
    {
        return $this->_numSuccesses + $this->_numFailures;
    }

    /**
     * Get number of successes
     *
     * @return int
     */
    public function getSuccessCount()
    {
        return $this->_numSuccesses;
    }

    /**
     * Get number of failures
     *
     * @return int
     */
    public function getFailureCount()
    {
        return $this->_numFailures;
    }

    /**
     * Add event
     * 
     * @param string $subject Event subject
     * @param Closure $event Event to execute when subject called
     * @return Mailer
     */
    public function addEvent($subject, Closure $event)
    {
        if (!is_string($subject)) {
            throw new InvalidArgumentException('$subject must be a string');
        }
        $this->_events[$subject][] = $event;
        return $this;
    }
}

/** Mailer */
$mailer = new Mailer();

$mailer->addEvent('mail', function($result, $to, $subject, $message) {
    // Code to log to database
});

$mailer->mail($to, $subject, $message);

// Execution order:
// 1. Mailer::mail()
// 2. Increase successes or failures, as appropriate
// 3. Execute 'mail' events
// 4. Closure with code to log to database executed

For number of sent, you can use a basic wrapper:

class Mailer
{
    /**
     * Events
     *
     * @var array
     */
    protected $_events = array();

    /**
     * Number of successful emails
     *
     * @var int
     */ 
    protected $_numFailures = 0;

    /**
     * Number of failed emails
     *
     * @var int
     */ 
    protected $_numSuccesses = 0;

    /**
     * Send email using PHP mail() function
     * 
     * @param string $to Send to email address
     * @param string $subject Email subject
     * @param string $message Email message
     * @param string $additionalHeaders Optional. Additional headers
     * @param string $additionalParams Optional. Additional params
     * @return Mailer
     */
    public function mail($to, $subject, $message, $additionalHeaders = '', $additionalParams = '')
    {
        $result = mail($to, $subject, $message, $additionalHeaders, $additionalParams);

        if ($result) {
            $this->_numSuccesses++;
        } else {
            $this->_numFailures++;
        }

        if (isset($this->_events['mail'])) {
            foreach ($this->_events['mail'] as $event) {
                $event($result, $to, $subject, $message);
            }
        }

        return $this;
    }

    /**
     * Get total number of emails sent
     *
     * @return int
     */
    public function count()
    {
        return $this->_numSuccesses + $this->_numFailures;
    }

    /**
     * Get number of successes
     *
     * @return int
     */
    public function getSuccessCount()
    {
        return $this->_numSuccesses;
    }

    /**
     * Get number of failures
     *
     * @return int
     */
    public function getFailureCount()
    {
        return $this->_numFailures;
    }

    /**
     * Add event
     * 
     * @param string $subject Event subject
     * @param Closure $event Event to execute when subject called
     * @return Mailer
     */
    public function addEvent($subject, Closure $event)
    {
        if (!is_string($subject)) {
            throw new InvalidArgumentException('$subject must be a string');
        }
        $this->_events[$subject][] = $event;
        return $this;
    }
}

/** Mailer */
$mailer = new Mailer();

$mailer->addEvent('mail', function($result, $to, $subject, $message) {
    // Code to log to database
});

$mailer->mail($to, $subject, $message);

// Execution order:
// 1. Mailer::mail()
// 2. Increase successes or failures, as appropriate
// 3. Execute 'mail' events
// 4. Closure with code to log to database executed
魔法少女 2024-11-22 18:02:54

您可以轻松记录通过 PHP 的 mail() 函数发出的任何邮件流量。

这是通过创建一个包装器来完成的,该包装器将处理以下两件事:记录和发送电子邮件。这相对容易完成,并且可以通过 php.ini 设置进行控制。

我可以推荐: 如何记录使用 PHP 的 mail() 函数发送的电子邮件以检测表单垃圾邮件(如果您运行的是 Linux)了解更多详细信息。

You can easily log any outgoing mail traffic that's going through PHP's mail() function.

This is done by creating a wrapper that will take care of both: logging and sending the emails. This is relativly easy to accomplish and can be controlled via php.ini settings.

I can recommend: How To Log Emails Sent With PHP's mail() Function To Detect Form Spam for more details if you're running linux.

一紙繁鸢 2024-11-22 18:02:54

作为电子邮件营销中的PHP新闻通讯脚本,我们通常会在电子邮件中插入小图片或小句子以使其不可见。 PHP函数将返回小图片的回显,将跟踪状态返回到您的邮件服务器。当您打开时事通讯并允许显示电子邮件中的所有图片时,此跟踪功能将被激活。

对于退回系统,必须参考服务器环境。只有当您在 VPS 或其他服务器中配置代码时,才能激活此功能。我相信你应该看到 http://www.phpnewsletter.org

As PHP newsletter script in the email marketing,we usually inserted a small picture or sentences in the email to make which invisible. The PHP function will give back the echo from the small pictures to return the tracking status to the your mail server. When you open the newsletter, and allow to appear all pictures in the email, this tracking function will be activated.

For the bounces system, it must refer to the server environment. Only when you configure the code in your VPS or some other server, this could be activated. I believe you should see http://www.phpnewsletter.org

咽泪装欢 2024-11-22 18:02:54

您可以通过向 php 脚本和邮件功能添加一些附加代码(对电子邮件消息进行更改)来跟踪电子邮件并获取已读回执。

以下链接可帮助您跟踪电子邮件阅读情况收据 - php 脚本

You can track emails and get read receipts by adding some additional code to the php script and mail funciton (changes to email message).

Here is a link which helps you to track email read receipts - php script

奶气 2024-11-22 18:02:54

(已编辑)

这里的基本概念是在 PHP 端记录发送。每条消息都会嵌入一些 HTML 和图像。当用户打开电子邮件时,图像将向服务器发起 ping 操作,发送电子邮件已打开(读取)的事实和日期(这可以来自服务器)以及其他信息,例如用于打开消息的邮件客户端(请求标头)。

对于提供的参数我并不完全确定。我知道您可以从某些类型的邮件服务器(例如 Microsoft Exchange)获取此信息,但我不知道您的标准 POP3 服务器是否支持此信息。

您可以使用此方法自动收集大量数据。它的工作原理实际上就像一个标准的网页广告跟踪器。对于服务器端,我推荐使用 Drupal 等 CMS 框架或 CodeIgniter 等 PHP 框架。

如果您使用 Drupal,那么大部分繁重的工作已经为您完成。您只需以您喜欢的方式组装拼图即可。我个人建议使用 MailChimp 来跟踪您的电子邮件。他们还有一个用于与其集成的 Drupal 模块 (http://drupal.org/project/mailchimp)。

(EDITED)

The basic concept here is that you record the sends on your PHP side. Each message will have some embedded HTML and an image. When the user opens the emails the image will launch a ping to the server sending the fact that the email was opened (read) and the date (this can come from the server) plus other information such as mail client used to open the message (request headers).

On the delivered parameters I am not entirely sure. I know that you can get this from certain types of mail servers (Microsoft Exchange for example), but I don't know if your standard POP3 servers support this.

You can collect a decent amount of data automatically with this method. It will work like a standard web page ad tracker really. For the server-side I would recommend a CMS framework such as Drupal or a PHP framework such as CodeIgniter.

If you go Drupal then most of the heavy lifting will already be done for you. You just have to assemble the puzzle pieces in a way that you like. Personally I would recommend using MailChimp to track your emails. They have a Drupal module for integrating with it as well (http://drupal.org/project/mailchimp).

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