我想在foreach循环的数组中应用一些条件。实际上,我有两个数组,以后将使用它们从脚本发送电子邮件。因此,我的第一个数组包含smtp电子邮件ID。第二个包含所有电子邮件ID。如
$email_arrays=$this->camp->get_contact_details(9);
$smtp_array=$this->camp->get_sender_details(10);
/* pre($email_arrays);
pre($smtp_array); */
$lastElement = end($smtp_array);
reset($smtp_array);
foreach ($email_arrays as $em) {
$current = current($smtp_array);
$current_smtp_email=$current['email'];
$dl=$current['daily_limit'];//current daily limit e.g.5 or 10 etc
//sendmail_test();
echo "Send email ".$em['email']." with smtp: ".$current_smtp_email . " <br/>";
next($smtp_array);
if ($lastElement === $current) {
reset($smtp_array);
}
}
我期望得到的输出按照我的要求是正确的。但是主要的问题是,我对smtp电子邮件ID设置了限制,以发送从另一个smtp表中获取的电子邮件。
Send email test1@example.com with smtp: smtp1@gmail.com
Send email test2@example.com with smtp: smtp2@gmail.com
Send email test3@example.com with smtp: smtp3@gmail.com
Send email test4@example.com with smtp: smtp1@gmail.com
Send email test5@example.com with smtp: smtp2@gmail.com
Send email test6@example.com with smtp: smtp3@gmail.com
Send email test7@example.com with smtp: smtp1@gmail.com
Send email test8@example.com with smtp: smtp2@gmail.com
Send email test9@example.com with smtp: smtp3@gmail.com
Send email test10@example.com with smtp: smtp1@gmail.com
Send email test11@example.com with smtp: smtp2@gmail.com
Send email test12@example.com with smtp: smtp3@gmail.com
Send email test13@example.com with smtp: smtp1@gmail.com
Send email test14@example.com with smtp: smtp2@gmail.com
Send email test15@example.com with smtp: smtp3@gmail.com
我已经成功创建了我想要的帐户。但是最主要的是,如果我对smtp1@gmail.com设置了限制(假设我已经应用了限制3),那么下一个smtp应该会发送电子邮件数组,也应该存储电子邮件计数。任何帮助将不胜感激。
我想要此输出。 如果我对smtp1@gmail.com设置了3个限制,则仅应触发3封电子邮件,然后迭代将继续使用数组中的另一个smtp
答案 0 :(得分:0)
尝试一些不同的方法,先使用smpt发送电子邮件,直到达到每日限制,然后再转到下一个:
$lastElement = end($smtp_array);
reset($smtp_array);
$current = current($smtp_array);
$current_smtp_email=$current['email'];
$dl=$current['daily_limit'];//current daily limit e.g.5 or 10 etc
$send[$current_smtp_email] = 1;
foreach ($email_arrays as $em) {
if ($send[$current_smtp_email] > $dl) {
if ($lastElement === $current) {
die ('No more SMTP to use today');
}
next($smtp_array);
$current = current($smtp_array);
$current_smtp_email=$current['email'];
$dl=$current['daily_limit'];
$send[$current_smtp_email] = 1;
}
echo "Send email ".$em['email']." with smtp: ".$current_smtp_email . " <br/>";
$send[$current_smtp_email]++;
}