我扫描收件箱的代码&找到发送失败的电子邮件地址。我需要做的是,如果这些电子邮件地址与数据库中现有的电子邮件地址匹配,它应该做的事情。 当我从收件箱中输出电子邮件地址时,它包含一些我无法摆脱的额外字符。 这是我的代码:
include 'dbconnect.php';
$hostname = "XXXXXX";
$inbox = imap_open($hostname, 'XXXXX', 'XXXXX');
if ($inbox)
{
function getBetween($message,$start,$end){
$temp= substr($message, 0, strpos($message, $end));
return substr($temp, strpos($temp, $start));
}
$date = date( "d-M-Y", strToTime( "-1 days" ));
$email=imap_search($inbox, 'SUBJECT "Mail delivery failed" SINCE "'.$date.'"',
SE_UID);
foreach($email as $email_number) {
$message = imap_fetchbody($inbox,$email_number,1);
$output.= '<div class="body">'.$message.'</div>';
$start = "The following address(es) failed:";
$end = "No Such User Here";
$newcontent = getBetween($message,$start,$end);
$final=str_replace("$start","","$newcontent");
$array=explode(' ',$final);
foreach($array as $value){
echo $value;
$data = mysql_fetch_array(mysql_query("SELECT * FROM invitations WHERE
email_invited='".$value."'"));
if($data[0] != NULL){
mysql_query("update invitations set invalid_email=1,success=0 where
email_invited='".$value."' limit 1") or die(mysql_error());
}
}
}
}
如果您想查看echo $value
下foreach($array as $value)
的输出,则完全如下:
hello@test.com hello@test.com hello@test.com hello@test.com hello@test.com soni.shanil@test.com sonishanil19@test.com
似乎由于这些空格,它无法搜索查询。我也尝试过str_replace(" ","","$final")
,但这也不行。
对此有何帮助?
答案 0 :(得分:1)
答案 1 :(得分:0)
看了一遍之后,我设法得到了我错过的trim()函数。我用它&amp;一切都很好。