ai didi

php - 获取每封电子邮件的用户名

转载 作者:行者123 更新时间:2023-11-29 06:21:02 24 4
gpt4 key购买 nike

首先是我的代码:

<?php

if(isset($betreff) && isset($text)){

$query= "SELECT email, anrede, vorname, nachname FROM newsletter";
$result= mysql_query ($query);
while ($row = mysql_fetch_array($result)) {
$anrede= $row['anrede'];
$vorname= $row['vorname'];
$nachname= $row['nachname'];
$email= $row['email'];

$text = str_replace('[A]', $anrede, $text);
$text = str_replace('[V]', $vorname, $text);
$text = str_replace('[N]', $nachname, $text);
$text = str_replace('[E]', $email, $text);
$body=$text;

strip_tags($text, '<br><b><img><a>');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Commeatus-IO <test@test.de>';
mail($email, $betreff, $body, $headers);
echo 'Email wurde gesendet an: ' . $email. '<br>';
}

?>

现在,如果我在文本中插入 [V](对于姓氏)或 [E] 用于电子邮件。但如果我这样做,它会在每封电子邮件中显示相同的姓氏和名字。为什么?

谢谢

最佳答案

这是因为您正在覆盖包含 [A][N][V][E] 占位符的文本,并且后续迭代无法再找到它们。

首先从 $text 提供你的 $body 变量,这样你就不会覆盖你的模板。

您还缺少循环末尾的右大括号。

您的代码应如下所示:

<?php

if(isset($betreff) && isset($text)){

$query= "SELECT email, anrede, vorname, nachname FROM newsletter";
$result= mysql_query ($query);
while ($row = mysql_fetch_array($result)) {
$anrede= $row['anrede'];
$vorname= $row['vorname'];
$nachname= $row['nachname'];
$email= $row['email'];

// feed $body with your template ($text)
$body = $text;
// use $body as the working copy (replace the placeholders in $body)
$body = str_replace('[A]', $anrede, $body);
$body = str_replace('[V]', $vorname, $body);
$body = str_replace('[N]', $nachname, $body);
$body = str_replace('[E]', $email, $body);

// I assume you wanted to strip tags in the e-mail text, not in the template
strip_tags($body, '<br><b><img><a>');

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Commeatus-IO <test@test.de>';
mail($email, $betreff, $body, $headers);
echo 'Email wurde gesendet an: ' . $email. '<br>';
}
}

?>

关于php - 获取每封电子邮件的用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33254651/

24 4 0
文章推荐: java - Hibernate - 如何创建 pojos 列表?
文章推荐: java - Appengine 没有编译我的 .jspx 文件
文章推荐: mysql - 无法使用 mysql 版本 0.3.20 创建 Rails 新应用程序
文章推荐: php - 如何在 __construct() 中创建 PDO 连接?
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com