取消订阅时事通讯
我想添加一个 linf 来取消签署我的时事通讯。我无法成功在时事通讯中提供我的变量“电子邮件”。 我同时将简讯发送到某个电子邮件地址 $template 允许新闻通讯从数据库获取数据,我的新闻通讯在 html 中,变量如下:{{variable}} 我尝试将我的代码模板放在我的 while 中,但电子邮件仍然是第一个 emai。 你有主意吗?
这是代码:
if($_POST['recipients']) {
$template = file_get_contents('template/emails/newsletter.html');
$addresses = explode(';', $_POST['recipients']);
$subject = stripslashes($_POST['subject']);
foreach($addresses as $address) {
$newsletter_unsign = ' <a href="http://dev.cater2.me/unsign-newsletter.php?id='.$address.'">Unsubscribe from the newsletter</a>.';
$template = str_replace(array('{{newsletter_top_bar}}','{{newsletter_top}}','{{newsletter_title1}}','{{newsletter_body1}}','{{newsletter_title2}}','{{newsletter_body2}}','{{newsletter_title3}}','{{newsletter_body3}}','{{newsletter_side_title}}','{{newsletter_side}}','{{newsletter_bottom}}','{{newsletter_footer}}','{{newsletter_unsign}}'),
array($_POST['newsletter_top_bar'],$_POST['newsletter_top'],$_POST['newsletter_title1'],$_POST['newsletter_body1'],$_POST['newsletter_title2'],$_POST['newsletter_body2'],$_POST['newsletter_title3'],$_POST['newsletter_body3'],$_POST['newsletter_side_title'],$_POST['newsletter_side'],$_POST['newsletter_bottom'],$_POST['newsletter_footer'], $newsletter_unsign),
$template);
$address = trim($address);
sendMail($address, $subject, str_replace('{{c2me_tracking_link}}', 'http://cater2.me/?ref='.urlencode(c2me_encrypt($address)), $template), true);
}
notif('E-mail(s) sent');
}
}
I want to add a linf to unsign to my newsletter. I can't succeed to give my variable "email" in the newsletter.
I send the newsletter to some email in the same time
$template allow to the newsletter to get data from database,and my newsletter in in html with variables like this: {{variable}}
I tried to put my code template in my while, but the email is still the first emai.
Do you have an idea?
here's the code:
if($_POST['recipients']) {
$template = file_get_contents('template/emails/newsletter.html');
$addresses = explode(';', $_POST['recipients']);
$subject = stripslashes($_POST['subject']);
foreach($addresses as $address) {
$newsletter_unsign = ' <a href="http://dev.cater2.me/unsign-newsletter.php?id='.$address.'">Unsubscribe from the newsletter</a>.';
$template = str_replace(array('{{newsletter_top_bar}}','{{newsletter_top}}','{{newsletter_title1}}','{{newsletter_body1}}','{{newsletter_title2}}','{{newsletter_body2}}','{{newsletter_title3}}','{{newsletter_body3}}','{{newsletter_side_title}}','{{newsletter_side}}','{{newsletter_bottom}}','{{newsletter_footer}}','{{newsletter_unsign}}'),
array($_POST['newsletter_top_bar'],$_POST['newsletter_top'],$_POST['newsletter_title1'],$_POST['newsletter_body1'],$_POST['newsletter_title2'],$_POST['newsletter_body2'],$_POST['newsletter_title3'],$_POST['newsletter_body3'],$_POST['newsletter_side_title'],$_POST['newsletter_side'],$_POST['newsletter_bottom'],$_POST['newsletter_footer'], $newsletter_unsign),
$template);
$address = trim($address);
sendMail($address, $subject, str_replace('{{c2me_tracking_link}}', 'http://cater2.me/?ref='.urlencode(c2me_encrypt($address)), $template), true);
}
notif('E-mail(s) sent');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
}
}
您仅从文件中获取
$template
一次,但随后尝试多次替换它。第一次替换后,它会被固定为第一个收件人的数据。尝试将替换的字符串分配给新变量,例如
$template_after_replace
:作为一项改进,您只需运行替换一次(在
foreach
循环之前替换那些不会出现的内容) t 更改(例如$_POST['newsletter_top']
),然后在foreach
循环中单独替换$newsletter_unsign
,但我将其保留为OP 的练习。You only fetch
$template
from the file once, but then you try to replace it multiple times. After the first replace, it is fixed with the first recipient's data.Try assigning the replaced string to a new variable, e.g.
$template_after_replace
:As an improvement, you can just run the replacement once (before the
foreach
loop to replace things that won't change (e.g$_POST['newsletter_top']
), then individually replace$newsletter_unsign
within theforeach
loop, but I will leave that as an exercise for the OP.