我坚持一个我无法解决的问题。我已经考虑了如何,查找它,并没有产生任何结果。
我试图在电子邮件中使用数组,我需要在它们之间进行双重换行。
我在mysql查询结果循环中创建两个数组,如下所示:
while($row = $result->fetch_assoc()){
$updated_email_array['Clinic']=$row['clinic_name'];
$updated_email_array['Email_Credits_To_Add']=$row['email_allotment'];
$updated_email_array['SMS_Credits_To_Add']=$row['sms_allotment'];
$updated_email_array['Email_Credits_Rolling_Over']=$row['$email_left'];
$display_email_array[] = $updated_email_array;
}
然后我解析出值并将它们添加到变量中以嵌套在电子邮件中,如下所示:
$intouch_credit_refill_message = "Credit Refill Report\n\n";
foreach ($display_email_array as $each_member) {
while (list($key, $value) = each ($each_member)) {
$intouch_credit_refill_message .= "$key: $value\n";
}
}
最后,我在电子邮件中发送$ intouch_credit_refill_message
mail($email address,"Credit Refill Record",$intouch_credit_refill_message,"From: email@address.com");
这给了我:
Credit Refill Report
Clinic: Royal York Animal Hospital
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 100200
Smail_Credits_Rolling_Over: 10050
New_Email_Credit_Allotment: 105200
New_SMS_Credit_Allotment: 10550
Clinic: Jason's Test Clinic
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 75000
Smail_Credits_Rolling_Over: 7500
New_Email_Credit_Allotment: 80000
New_SMS_Credit_Allotment: 8000
但我需要:
Credit Refill Report
Clinic: Royal York Animal Hospital
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 100200
Smail_Credits_Rolling_Over: 10050
New_Email_Credit_Allotment: 105200
New_SMS_Credit_Allotment: 10550
Clinic: Jason's Test Clinic
Email_Credits_To_Add: 5000
SMS_Credits_To_Add: 500
Email_Credits_Rolling_Over: 75000
Smail_Credits_Rolling_Over: 7500
New_Email_Credit_Allotment: 80000
New_SMS_Credit_Allotment: 8000
我无法弄清楚如何在循环中的数组之间添加这样的中断,并将它们添加到电子邮件行中。
感谢您提供任何帮助。
答案 0 :(得分:1)
只需在foreach循环中添加另一个新行:
foreach ($display_email_array as $each_member) {
while (list($key, $value) = each ($each_member)) {
$intouch_credit_refill_message .= "$key: $value\n";
}
$intouch_credit_refill_message .= "\n";
}
答案 1 :(得分:0)
如果您需要换行符或选项卡,那么在PHP中的任何时候都可以执行此操作
echo "\r\n";
echo "\t";
如果您想要新的广告系列,并且希望跨平台,也可以使用PHP_EOL
。
PHP_EOL(string) 此平台的正确“行尾”符号。自PHP 5.0.2起可用