I have a simple mail() script that sends to multiple emails dynamically by seperating the emails with commas.
我有一个简单的mail()脚本,通过用逗号分隔电子邮件动态发送到多个电子邮件。
<?php
$sendto = array("email@gmail.com", "email@zoho.com", "email@mail.usf.edu");
foreach ($sendto as $email)
{
if ($email is the last indice in the array..) // <-- here
$to = $email;
else
$to = $email . ', ';
}
$subject = "test message";
$msg = "this is a test";
if (mail($to, $subject, $msg))
echo "message sent";
else
echo "uh oh";
?>
How do I identify if (this is the last piece of data in my array) ?
如何识别(这是我的数组中的最后一块数据)?
3 个解决方案
#1
3
php includes implode
or join
which will work much better here:
php包括implode或join,这将在这里工作得更好:
$to = implode(', ', $sendto);
#2
5
No need.
没必要。
$to = implode(', ', $sendto);
#1
3
php includes implode
or join
which will work much better here:
php包括implode或join,这将在这里工作得更好:
$to = implode(', ', $sendto);
#2
5
No need.
没必要。
$to = implode(', ', $sendto);