gpt4 book ai didi

php - 使用从数据库中选择的不同数据发送组邮件

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

我在使用下面的代码发送群组邮件时遇到了一些问题。错误是 fatal error :

Cannot redeclare clean_string() (previously declared in /home/content/83/11173683/html/AA/sendcanteen.php:74)

<?php
$d = $_REQUEST['date']; //requesting date from canteendetails.php

include("dboperation.php");
$obj = new dboperation();
$n = array();
$e = array();
$str = "select * from employee2";
$result = $obj->selectquery($str);
while ($r = mysql_fetch_assoc($result)) {
$n[] = $r['emp_name'];
$e[] = $r['email'];
}
for ($i = 0; $i < sizeof($n); $i++) {

$str1 = "select * from modifycanteen where name='$n[$i]' and date='$d'";
$result1 = $obj->selectquery($str1);
$r = mysql_fetch_assoc($result1);
$email_to = $r['email'];
$coffee = $r['coffee'];
$tea = $r['tea'];
$remarks = $r['remarks'];

$email_subject = "CANTEEN DETAILS";

$email_from = "Catering Services";

$body = '
<html>
<head>
<style>

body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left: 10em;
margin-top: 1em;
font-family: "verdana";
font-size: 10pt;
font-weight:bold ;
color: "000000";
}

</style>
</head>
</body>
';
$message = "Mr/Mrs " . $n[$i] . "\nYour Canteen details";
$c = "No: of Coffee :" . $coffee . "\n ";
$t = "No: of Tea :" . $tea . "\n ";
$rem = "Remarks :" . $remarks . "\n ";

$bodys .= "$message<br>";
$bodys .= "$c<br>";
$bodyss .= "$t<br>";
$bodysss .= "$rem";

$body = $body . $bodys . $bodyss . $bodysss;

function clean_string($string)
{
$bad = array(
"content-type",
"bcc:",
"to:",
"cc:",
"href"
);
return str_replace($bad, "", $string);
}
$email_message .= "Message: " . clean_string($message) . "\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: Accounttoall.com <http://www.redboat.in/>' . "\r\n";

@mail($email_to, $email_subject, $body, $headers);
}
if (@mail) {
header("location:canteendetails.php");
} else {
echo "MAIL IS NOT SENT";
}
?>

最佳答案

一个函数只能定义一次

为什么要在 for 循环中定义函数clean string

您必须在 for 循环之外定义函数

试试这个

<?php
function clean_string($string)
{
$bad = array(
"content-type",
"bcc:",
"to:",
"cc:",
"href"
);
return str_replace($bad, "", $string);
}

$d = $_REQUEST['date']; //requesting date from canteendetails.php

include("dboperation.php");
$obj = new dboperation();
$n = array();
$e = array();
$str = "select * from employee2";
$result = $obj->selectquery($str);
while ($r = mysql_fetch_assoc($result)) {
$n[] = $r['emp_name'];
$e[] = $r['email'];
}
for ($i = 0; $i < sizeof($n); $i++) {

$str1 = "select * from modifycanteen where name='$n[$i]' and date='$d'";
$result1 = $obj->selectquery($str1);
$r = mysql_fetch_assoc($result1);
$email_to = $r['email'];
$coffee = $r['coffee'];
$tea = $r['tea'];
$remarks = $r['remarks'];

$email_subject = "CANTEEN DETAILS";

$email_from = "Catering Services";

$body = '
<html>
<head>
<style>

body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left: 10em;
margin-top: 1em;
font-family: "verdana";
font-size: 10pt;
font-weight:bold ;
color: "000000";
}

</style>
</head>
</body>
';
$message = "Mr/Mrs " . $n[$i] . "\nYour Canteen details";
$c = "No: of Coffee :" . $coffee . "\n ";
$t = "No: of Tea :" . $tea . "\n ";
$rem = "Remarks :" . $remarks . "\n ";

$bodys .= "$message<br>";
$bodys .= "$c<br>";
$bodyss .= "$t<br>";
$bodysss .= "$rem";

$body = $body . $bodys . $bodyss . $bodysss;


$email_message .= "Message: " . clean_string($message) . "\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: Accounttoall.com <http://www.redboat.in/>' . "\r\n";

@mail($email_to, $email_subject, $body, $headers);
}
if (@mail) {
header("location:canteendetails.php");
} else {
echo "MAIL IS NOT SENT";
}
?>

关于php - 使用从数据库中选择的不同数据发送组邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com