1

我需要在用户订阅完成时发送的电子邮件正文中添加一个链接。然后,此链接应向一个地址发送一封电子邮件,该地址表明“用户名”要续订其订阅。所以我需要在 php mail() 中做一个 php mail(),如果你理解我的话!此外,在他们单击链接后,他们应该会收到一条感谢消息。当前 'sendExpiryEmail' 函数的 php 代码如下。希望你能帮忙!谢谢。

公共函数 sendExpiryEmail($emails){

    foreach($emails as $email){

        $name = $email['name'];

        $emailaddress = $email['email'];

        $expirydate = date('jS F Y',strtotime($email['datetime_expire']));



        $subject = "AZ China Report expiry reminder";



        $body = '<p><img src="http://az-china.com/images/azchina_logo_email.jpg"></p>

                <p>Dear '.$name.',<br /><br />

                We hope you have been enjoying your subscription to the Black China Report.<br /><br />

                We aim to meet the needs of our readers, by de-mystifying the China market, and by providing accurate, current and pertinent facts and analysis.<br />

                We have some exciting new initiatives planned in the coming months.<br /><br />

                Your Black China Report subscription will expire on '.$expirydate.'.<br /><br />

                <strong>Renewing your subscription is easy.</strong><br /><br />

                Simply click here (link to mail()) and we will send you an order form and details on how to pay.<br /><br />

                If we can be any further assistance, please do not hesitate to contact us! <br /><br />

                Yours sincerely, <br /><br />

                Tom Martin<br /><br />

                AZ China</p>';



        // multiple recipients

        $to  = $emailaddress;

        //$to = 'c23gooey@gmail.com';



        // To send HTML mail, the Content-type header must be set

        $headers  = 'MIME-Version: 1.0' . "\r\n";

        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";



        // Additional headers

        $headers .= 'From: AZ China <tom.martin@az-china.com>' . "\r\n";



        // Mail it

        mail($to, $subject, $body, $headers);

    }

}
4

1 回答 1

0

处理此问题的一种方法是设置一个查找表或联结表,您将在其中存储一个唯一标识 ID,该 ID 是您为每个续订请求生成的具有相应用户 ID 的。

此表可能类似于:

renewals
-------------------------------
renewid              | userid
-------------------------------
[output of uniqid()] | bob
[output of uniqid()] | bill
[output of uniqid()] | sarah
...

当您运行脚本来收集即将到期的帐户列表时,请在电子邮件步骤中添加一点:

while ...

    $renewid = uniqid();

    $renewurl = "http://.../renew.php?req=$renewid";

    // Put that URL in the body of the email.

    $renewsql = "
INSERT INTO renewals (
    renewid, userid
) VALUES (
    '$renewid', '{$email['userid']}'
)
";

    if ($db->query($renewsql)) {
        mail(...);
    }
}

假设这$email['userid']就是用户 ID 字段的名称,并且您已在查询中选择了它$emails

然后,使用类似的 URL http://.../renew.php?req=$renewid,您可以在以下位置执行类似的操作renew.php

<?php

$renew = preg_replace('/^a-z0-9/i', '', $_GET['req']);

if ($renew != '') {
    $which = $db->query("
SELECT userid 
FROM renewals 
WHERE renewid = '$renew' 
LIMIT 1
");

    if ($which->hasRows()) {
        $userid = $which->get(0)->field('userid');

        // do whatever renewal stuff with the $userid

        $db->query("DELETE FROM renewals WHERE renewid = '$renewid'");
    } 
}

您可以做的另一件事是添加一个expires列,以便您可以定期清除旧的续订请求。但或多或少,这是一般的想法。

于 2013-03-26T07:42:31.220 回答