php - 使用 Amazon SES 通过 PHP 发送时,并非所有邮件都会被收件人收到

标签 php mysql codeigniter newsletter amazon-ses

我编写了简单的 PHP (codeigniter) 脚本来使用 Amazon SES 发送新闻通讯。我在 MySQL 表和脚本中有大约 8000 封电子邮件,它提取所有行(电子邮件地址),将其拆分为较小的包(由于 SES 限制)并通过 SMTP 发送电子邮件。我正在使用 sleep()* 和每分钟运行一次的 cronjob。我知道这不是最好的解决方案,但作为一个概念,它工作得很好。

要允许使用 bcc 发送邮件,我必须确保 to 字段中至少有一个收件人,否则 Amazon SES 将不会发送邮件。因此,我的地址 (news@baulink.rs) 始终位于 to 中,其他地址位于 bcc 中。每次迭代都会在 bcc 中放入 8 个不同的地址(顺便说一句,有没有更好的解决方案?)。我还有一个简单的日志文件,其中写入了我的应用程序操作的每个地址。

据我所知,一些收件人没有收到新闻通讯。 Amazon SES 返回退回的电子邮件并且工作正常,但某些地址根本无法收到邮件,并且 Amazon SES 没有任何反馈。这些地址在我的日志中,这意味着它们是由 PHP 脚本处理的。然后我删除该地址并再次插入 MySQL 表中 - 它起作用了!有些电子邮件是从 CSV 文件解析的,有些是手动插入的。我真的不知道也无法与所有收件人核实他们是否收到了新闻通讯。您知道什么可能导致这种奇怪的行为吗?

我不知道问题出在哪里。

我正在使用 CodeIgniter 和 PHPMailer。

 public function cronSendMail(){
    $newsletter = $this->baumodel->getNewsletter();

    if(is_array($newsletter)){
        echo "No job for me!";    
        return;
    }elseif(is_object($newsletter)){ //means there is a newsletter ready for sending                        
        $limit = 104;
        $newsOfset = $newsletter->news_slanje_ofset;                        
        $noviOfset = $newsOfset+$limit;

        $adrese = $this->baumodel->getAdresar($limit, $newsOfset); 
        $brojAdresa = count($this->baumodel->getSveAdrese()); //number of recipients in whole MySQL table

        if($brojAdresa < $newsOfset){ 
            echo "Adrese: ".$brojAdresa;
            echo " Ofset: " .$newsOfset;
            die('Job is finished! ');
        }

        $this->baumodel->setNewsletterOfset($newsletter->news_id, $noviOfset);                      
        $emailArray = array();

        foreach($adrese as $adr){
            array_push($emailArray, trim($adr['adr_email']));
        }

        $newsletterContent = $newsletter->news_sadrzaj;                                                                                     
        $this->load->library('email');
        $this->email->clear();                

        $maliNiz = array();
        for($i=0; $i<13; $i++){
            //13 times with 2 seconds sleep is ~30-35 seconds of execution time.
            //CronJob runs every minute
            $j=0;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;                           
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;
            $maliNiz[$j] = array_pop($emailArray);
            $j++;                           

            $this->email->to('news@baulink.rs');
            $this->email->bcc($maliNiz); //This is my BCC array of 8 addresses
            $this->email->from('office@baulink.rs', 'Baulink Portal');
            $this->email->subject('Gradjevinski portal Baulink - Novo na portalu');
            $this->email->message($newsletterContent);
            $this->email->send();
            //echo $this->email->print_debugger();

            sleep(2);               

            //log file start
            $filepath = APPPATH . 'logs/mail-log-' . date('Y-m-d') . '.php';
            $handle = fopen($filepath, "a+");                                                       
            $currentDateTime = date('d.M.Y H:i:s');
            foreach($maliNiz as $emailAdresa){
                    $infoLog = $emailAdresa . " // ".$currentDateTime . " \n";
                    fwrite($handle, $infoLog);
            }
            fclose($handle);
            //log file end
        }
    }
}

最佳答案

根据亚马逊文档,这可能是问题所在。

Important When you send an email to multiple recipients (recipients are "To", "CC", and "BCC" addresses) and the call to Amazon SES fails, the entire email is rejected and none of the recipients will receive the intended email. We therefore recommend that you send an email to one recipient at a time.

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-email.html

关于php - 使用 Amazon SES 通过 PHP 发送时,并非所有邮件都会被收件人收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597056/

相关文章:

codeigniter:登录后如何重定向到当前 Controller (常规 php 中的 php_self)

PHP foreach 数据库结果

javascript - 脚本在 Wordpress 中被加载不止一次

php - 计算不同列中相同的值mysql

php - 通过 python 或 php 从 gmail 中获取附件

sql - 从最好的行中返回随机行(即 : 100 rows -> best 10 -> get 5 random)

php - 使用 MySQL(和 PHP)搜索可用性?

mysql - 删除mysql中字段的最后一个字符

php - 查询中的 Symfony 1 Doctrine 查询

linux - 如何从服务器 url 中排除其他域?