Problem with sending some mails at once

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
alexd1991
Forum Newbie
Posts: 1
Joined: Wed Jan 09, 2013 3:08 am

Problem with sending some mails at once

Post by alexd1991 »

Hey,

I'm want to use swift mailer to send some mails at the same time.
But it doesent work :(

Code: Select all

foreach($id as $key => $value){
    if($value[1]=="on" && $value[2] !=""){
        $message = Swift_Message::newInstance($betreff)
            ->setFrom(array($row['email'] => $_SESSION['vname']." ".$_SESSION['nname']))
            ->setTo(array($value[2]))
            ->setBody($mailtext)
            ->setReturnPath($row['email'])
            ->setContentType("text/html")
        ;
        
        $transport = Swift_MailTransport::newInstance();
        $mailer = Swift_Mailer::newInstance($transport); 
        
        if($mailer->send($message)){
            echo "OK";
        }else{
            echo "ERROR";
        }
        
    }
}  
The email adresses are in $id, exactly in $value[2].

Im always getting this error below:
[text]Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.'
in .../swift/lib/classes/Swift/Mime/Headers/MailboxHeader.php:352
Stack trace:
#0 .../swift/lib/classes/Swift/Mime/Headers/MailboxHeader.php(264): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('')
#1 .../swift/lib/classes/Swift/Mime/Headers/MailboxHeader.php(108): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 .../swift/lib/classes/Swift/Mime/Headers/MailboxHeader.php(65): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 .../swift/lib/classes/Swift/Mime/SimpleMimeEntity.php(588): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)[/text]

Where is the problem and how can i fix it?
I cant send the mails as one mail with all the adresses at once, because i need to check if every mail was sent or not.

Thanks ;)
bennot
Forum Newbie
Posts: 3
Joined: Tue Feb 05, 2013 2:26 am

Re: Problem with sending some mails at once

Post by bennot »

maybe you can find a solution in my code :) and maybe you can help me too

viewtopic.php?f=52&t=137349
Post Reply