退订广告被任意删除
Unsubscribe blurb arbitrarily being removed
我正在通过 CRON 作业使用 PHP 和 Mailgun,该作业将电子邮件发送到订阅的电子邮件地址,计划每天 运行 尽管可能不会每天都有电子邮件排队。
我遇到的问题是,在测试期间 运行s 似乎在发送电子邮件之前我拥有的退订宣传语被任意删除。
这是我用来添加退订宣传语的代码:
$email = array(
'subject' => $row['subject'],
'body' => $row['body'] . "\r\n\r\n\r\n\r\n\r\n" . "No longer wish to receive emails from us? You may unsubscribe below. Beware, in unsubscribing, you will miss out on any information we share via email going forward."
);
值得一提的是 $row['subject']
是一个带有 HTML 标记的字符串。
这是我用来 A) 在发送电子邮件之前执行邮件合并和 B) 实际发送电子邮件的代码。
function send_email($from, $to, $subject, $body) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:removed for privacy');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/removed for privacy/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'from' => $from,
'to' => $to,
'subject' => $subject,
'html' => $body
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function mail_merge($text, $agency, $sender, $receiver, $efs) {
// Replace any mail merger fields from the body
$text = str_replace('[agency.name]', $agency['name'], $text);
$text = str_replace('[agency.address]', $agency['address_formatted'], $text);
$text = str_replace('[agency.phone]', $agency['phone'], $text);
$text = str_replace('[agency.fax]', $agency['fax'], $text);
$text = str_replace('[agency.email]', $agency['email'], $text);
$text = str_replace('[agency.signature]', $agency['signature'], $text);
$text = str_replace('[agency.referral]', $agency['referral'], $text);
$text = str_replace('[sender.firstname]', $sender['first_name'], $text);
$text = str_replace('[sender.lastname]', $sender['last_name'], $text);
$text = str_replace('[sender.email]', $sender['email'], $text);
$text = str_replace('[sender.signature]', $sender['signature'], $text);
$text = str_replace('[receiver.firstname]', $receiver['first_name'], $text);
$text = str_replace('[receiver.lastname]', $receiver['last_name'], $text);
$text = str_replace('[receiver.email]', $receiver['email'], $text);
$text = str_replace('[receiver.phone]', $receiver['phone'], $text);
$text = str_replace('[efs.firstname]', $efs['first_name'], $text);
$text = str_replace('[efs.lastname]', $efs['last_name'], $text);
$text = str_replace('[efs.email]', $efs['email'], $text);
$text = str_replace('[efs.phone]', $efs['phone'], $text);
return $text;
}
正如我所提到的,我遇到的情况是 一些 发送的测试电子邮件不包括附加的新行和退出简介。这是在执行 cURL 请求以通过 Mailgun 的 API 发送电子邮件时可能导致的,还是我在代码中无意中做的事情,只是没有捕捉到?
虽然我一直无法弄清楚为什么广告被任意删除,但我能够通过在 MailGun 中从我的域的控制面板自定义取消订阅模板来解决我的问题:
Domains > [Domain Name] > Tracking Settings > Customize unsubscribe templates
我正在通过 CRON 作业使用 PHP 和 Mailgun,该作业将电子邮件发送到订阅的电子邮件地址,计划每天 运行 尽管可能不会每天都有电子邮件排队。
我遇到的问题是,在测试期间 运行s 似乎在发送电子邮件之前我拥有的退订宣传语被任意删除。
这是我用来添加退订宣传语的代码:
$email = array(
'subject' => $row['subject'],
'body' => $row['body'] . "\r\n\r\n\r\n\r\n\r\n" . "No longer wish to receive emails from us? You may unsubscribe below. Beware, in unsubscribing, you will miss out on any information we share via email going forward."
);
值得一提的是 $row['subject']
是一个带有 HTML 标记的字符串。
这是我用来 A) 在发送电子邮件之前执行邮件合并和 B) 实际发送电子邮件的代码。
function send_email($from, $to, $subject, $body) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:removed for privacy');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/removed for privacy/messages');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'from' => $from,
'to' => $to,
'subject' => $subject,
'html' => $body
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function mail_merge($text, $agency, $sender, $receiver, $efs) {
// Replace any mail merger fields from the body
$text = str_replace('[agency.name]', $agency['name'], $text);
$text = str_replace('[agency.address]', $agency['address_formatted'], $text);
$text = str_replace('[agency.phone]', $agency['phone'], $text);
$text = str_replace('[agency.fax]', $agency['fax'], $text);
$text = str_replace('[agency.email]', $agency['email'], $text);
$text = str_replace('[agency.signature]', $agency['signature'], $text);
$text = str_replace('[agency.referral]', $agency['referral'], $text);
$text = str_replace('[sender.firstname]', $sender['first_name'], $text);
$text = str_replace('[sender.lastname]', $sender['last_name'], $text);
$text = str_replace('[sender.email]', $sender['email'], $text);
$text = str_replace('[sender.signature]', $sender['signature'], $text);
$text = str_replace('[receiver.firstname]', $receiver['first_name'], $text);
$text = str_replace('[receiver.lastname]', $receiver['last_name'], $text);
$text = str_replace('[receiver.email]', $receiver['email'], $text);
$text = str_replace('[receiver.phone]', $receiver['phone'], $text);
$text = str_replace('[efs.firstname]', $efs['first_name'], $text);
$text = str_replace('[efs.lastname]', $efs['last_name'], $text);
$text = str_replace('[efs.email]', $efs['email'], $text);
$text = str_replace('[efs.phone]', $efs['phone'], $text);
return $text;
}
正如我所提到的,我遇到的情况是 一些 发送的测试电子邮件不包括附加的新行和退出简介。这是在执行 cURL 请求以通过 Mailgun 的 API 发送电子邮件时可能导致的,还是我在代码中无意中做的事情,只是没有捕捉到?
虽然我一直无法弄清楚为什么广告被任意删除,但我能够通过在 MailGun 中从我的域的控制面板自定义取消订阅模板来解决我的问题:
Domains > [Domain Name] > Tracking Settings > Customize unsubscribe templates