gpt4 book ai didi

PHP Mailer - 邮件正文中的 foreach

转载 作者:行者123 更新时间:2023-12-03 02:56:06 26 4
gpt4 key购买 nike

我想在电子邮件正文中包含使用 foreach 的结果。当我添加 foreach 语句时,PHP Mailer 似乎只是切断了消息。关于如何在消息正文中包含多个结果有什么想法吗?

$mail->Body    = '*** Automated email - do not reply ***<br><br>Hello '.$Name.', <br><br>We were able to connect you with the following services. <br><br> ';
foreach($findResult['data'] as $key=>$findData){
if($findData['CompanyEmail'][0] != NULL || $findData['CompanyPhone'][0] != NULL) {
echo $findData['CompanyName'][0];
echo $findData['CompanyContact'][0];
echo $findData['CompanyPhone'][0];
echo $findData['ContactEmail'][0];
}?><br><?php }
$body .='<br><br>Thank you for using our directory.<br><br><br>Regards,<br><br>Sender';

附注如果我去掉“;”在 foreach 之前,我收到错误。

最佳答案

您需要使用 $mail->Body .= 来继续字符串,而不是使用 echo。像这样:

$mail->Body    = '*** Automated email - do not reply ***<br><br>Hello '.$Name.', <br><br>We were able to connect you with the following services. <br><br> ';
foreach($findResult['data'] as $key=>$findData){
if($findData['CompanyEmail'][0] != NULL || $findData['CompanyPhone'][0] != NULL) {
$mail->Body .= $findData['CompanyName'][0];
$mail->Body .= $findData['CompanyContact'][0];
$mail->Body .= $findData['CompanyPhone'][0];
$mail->Body .= $findData['ContactEmail'][0];
}
}
$body .='<br><br>Thank you for using our directory.<br><br><br>Regards,<br><br>Sender';

如果正如我怀疑的那样,$body 也应该是电子邮件的一部分,那么也将其更改为 $mail->Body .=

关于PHP Mailer - 邮件正文中的 foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21190297/

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