При отправке двух писем, второе не отправляется

Столкнулся с проблемой, что swift mailer перестал отправлять письма. Решил написать свою функцию mail, но она так же не отправляет. Оказалось, что первое письмо отправляется, а второе не отправляется. Если меняю местами, то отправляется только то, которое первое стоит в коде. Что делать? Из идей только какую-нибудь паузу поставить

PS: класс отправки письма

<?php

namespace app\modules;

class Mailer
{
    public function Send($to, $fromSite, $fromEmail, $subject, $files)
    {
        // Message 
        $htmlContent = '<p></p>';
        // Header for sender info
        //$headers  = "Content-type: text/html; charset=utf-8\r\n"; 
        $headers .= "From: От кого письмо ".$fromSite." ".$fromEmail."\r\n"; 
        $headers .= "Reply-To: ".$fromEmail."\r\n"; 


        $uploadStatus = 1;
        if (!empty($files['Elect']['name']['file']))
        {
            // File path config
            $targetDir = "uploads/";
            $fileName = basename($files["Elect"]["name"]["file"]);
            $targetFilePath = $targetDir . $fileName;

            $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
            // Allow certain file formats
            $allowTypes = array('pdf', 'doc', 'docx', 'jpg', 'png', 'jpeg');
            if(in_array($fileType, $allowTypes))
            {
                // Upload file to the server
                if(move_uploaded_file($files["Elect"]["tmp_name"]["file"], $targetFilePath)){
                    $uploadedFile = $targetFilePath;
                } else {
                    $uploadStatus = 0;
                    $statusMsg = "Файл не был загружен";
                }
            }
            else
            {
                $uploadStatus = 0;
                $statusMsg = 'Необходимый формат для загрузки: PDF, DOC, JPG, JPEG, & PNG';
            }
        }
        
        if($uploadStatus == 1)
        {
            if(!empty($uploadedFile) && file_exists($uploadedFile))
            {
                // Boundary 
                $boundary  = md5(time()); 
                //$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
                
                $headers .= "MIME-Version: 1.0\r\n"; // Defining the MIME version
                $headers .= "Content-Type: multipart/mixed;"; // Defining Content-Type
                $headers .= "boundary = ".$boundary ."\r\n"; //Defining the Boundary
                
                // Multipart boundary 
                $message = "--".$boundary."\r\n";
                //$message .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
                $message .= "Content-type: text/html; charset=utf-8\r\n"; 
                $message .= "Content-Transfer-Encoding: base64\r\n\r\n";
                $message .= chunk_split(base64_encode($htmlContent));
                
                $fp =    @fopen($uploadedFile,"rb");
                $data =  @fread($fp,filesize($uploadedFile));
                @fclose($fp);
                $data = chunk_split(base64_encode($data));
                
                $message .= "--".$boundary."\r\n";
                $message .="Content-Type: ".$type."; name=".basename($uploadedFile)."\r\n";
                $message .="Content-Disposition: attachment; filename=".basename($uploadedFile)."\r\n";
                $message .="Content-Transfer-Encoding: base64\r\n";
                $message .="X-Attachment-Id: ".rand(1000, 99999)."\r\n\r\n";
                $message .= $data; // Attaching the encoded file with email
                
                // Preparing attachment
                if(is_file($uploadedFile))
                {
                    $t = 1;
                }               
                // Send email
                $mail = mail($to, $subject, $message, $headers);
                
                // Delete attachment file from the server
                @unlink($uploadedFile);
            }
            else
            {
                // Set content-type header for sending HTML email
                $headers .= "Content-type: text/html; charset=utf-8\r\n"; 
                
                // Send email
                $mail = mail($to, $subject, $htmlContent, $headers); 
            }
            
            // If mail sent
            if($mail){
                $statusMsg = 'Your contact request has been submitted successfully !';
                $msgClass = 'succdiv';
                
                $postData = '';
            }else{
                $statusMsg = 'Your contact request submission failed, please try again.';
            }
        }
            
        
        //var_dump($files);
        
        //mail($to, $subject, $htmlContent, $headers);
        return $mail;
    }
}
?>

И далее в функции контроллера вызывается и проверяется:

$mailer_obj1 = new Mailer()
$m1 = $mailer_obj1->Send(Yii::$app->params['email1'], Yii::$app->params['HOST'], Yii::$app->params['fromEmail'], $subject, $_FILES);
            
$mailer_obj2 = new Mailer();
$m2 = $mailer_obj2->Send(Yii::$app->params['email2'], Yii::$app->params['HOST'], Yii::$app->params['fromEmail'], $subject, $_FILES);

if($m1 && &m2) // В это условие не заходит, так как второе письмо не отправилось
{
    
}

Если поменять местами $m1 и $m2 при создании объекта и отправки письма, то $m2 отправится, а $m1 нет


Ответы (0 шт):