php - 从 imap_search() 读取电子邮件时出现额外字符

标签 php mysql imap

我有代码可以扫描我的收件箱并查找发送失败的电子邮件地址。我需要做的是,如果这些电子邮件地址与数据库中现有的电子邮件地址匹配,它应该执行此操作。 当我从收件箱中获取电子邮件地址的输出时,它包含一些我无法删除的额外字符。 这是我的代码:

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/

相关文章:

php - 插入前检查记录是否存在

php - PHP explode() 函数的使用

php - 根据编码翻译 IMAP 正文

ssl - 为什么 thunderbird 78 在与 IMAP 邮件服务器通话时会挂起?

php - 从 obj c 的 URL 中删除 %2520 和其他非标准字符

php - 在php中将数组字段插入mysql

php - 插入 IF 条件,ELSE 什么都不做,MySQLi

mysql - 英国和美国日期的混合 - 全部转换为英国

php - 将 mySQL 数据库的日志文件日期时间格式从 12 小时制批量转换为 24 小时制

php - php for 循环出现错误 500