我有代码可以扫描我的收件箱并查找发送失败的电子邮件地址。我需要做的是,如果这些电子邮件地址与数据库中现有的电子邮件地址匹配,它应该执行此操作。 当我从收件箱中获取电子邮件地址的输出时,它包含一些我无法删除的额外字符。 这是我的代码:
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());
}
}
}
}
如果您想查看 foreach($array as $value)
下 echo $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")
,但效果不佳。
有什么帮助吗?
最佳答案
哇,多好的 SQL 注入(inject)啊。 请考虑使用参数化查询。现在是 2014 年,十年前就已经被打破了。您的应用程序很容易受到攻击,有人会通过它来攻击您。
关于php - 从 imap_search() 读取电子邮件时出现额外字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22574986/