Page 1 of 1

How to send messages witch are not send the first time

Posted: Wed Jan 14, 2009 3:21 pm
by brandweerman
I have a problem.

i'm using swift mailer and i've got a problem with sending. The mailer fails several mail adresses.
I need to build in the script some kind of loop which checks in the mysql database which mailadresses are send correctly and which not.
The ones that didnt send needs to be send again.

I tryd for days to figure it out but i'm really stuck...

Below i post the scipt i'm using. Hopefully one of you can help me make the send loop and check...

Thanks in advance....

Code: Select all

 
 
$hostname = '********';  
$username = '********';  
$password = '********';  
$database = '********'; 
 
mysql_connect("$hostname","$username","$password");  
mysql_select_db("$database");
 
    require_once "lib/Swift.php";
    require_once "lib/Swift/Log.php";
    require_once "lib/Swift/LogContainer.php";
    require_once "lib/Swift/Connection/SMTP.php";
    require_once "lib/Swift/Plugin/Decorator.php";
    require_once "lib/Swift/Plugin/AntiFlood.php";
 
    $log            = Swift_LogContainer::getLog();
    $log->setLogLevel(3);
    $conn =& new Swift_Connection_SMTP("smtp1.********.net", 25);
    $conn->setUsername("noreply@********.com");
    $conn->setpassword("********");
 
 
    $swift            = new Swift ($conn);
    $from            = new Swift_Address ('noreply@********.com', 'Mailing');
    $subj            = 'Mailing';
    $body            = 'My HTML mailing';
        
 
    $msg            = new Swift_Message ($subj, $body, 'text/html');
    $recipients        = new Swift_RecipientList();
    
        $sql = "SELECT email, naam FROM mailing";      
        $result = mysql_query($sql);      
 
        $to = array(); 
        $replacements = array(); 
 
        while($aRow = mysql_fetch_assoc($result)){ 
        
            $to[] = new Swift_Address ($aRow['email']); 
            $replacements[$aRow['email']] = array('{naam}' => $aRow['naam']); 
            
        } 
        
    $swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator"); 
    foreach ($to as $address) { 
        $recipients->addTo ($address); 
    } 
    
        
    //Reconnect after 20 emails, but wait for 5 seconds first
    $swift->attachPlugin(new Swift_Plugin_AntiFlood(20, 5), "anti-flood");
 
    $number_sent = $swift->batchSend ($msg, $recipients, $from);
    $swift->disconnect ();
    echo 'De mailing failed at the following recipients:';
    echo '<pre>';
    print_r ($log->getFailedRecipients());
    echo '</pre>';
    echo 'Message sent to ' . $number_sent . ' recipients.';
 
 
 
 

Re: How to send messages witch are not send the first time

Posted: Fri Jan 16, 2009 2:30 am
by jmut
http://www.ibm.com/developerworks/opens ... php-batch/

This might be interesting read. In short you should have such tasks put in a spool. And then have a crontab that executes them. You have a flag per task if success or not.

Re: How to send messages witch are not send the first time

Posted: Sun Jan 18, 2009 3:34 pm
by brandweerman
Wow,

Hard stuff to read...
Don't understand it all, but i'm gonna give it a try...

Ideas are welcome...

Re: How to send messages witch are not send the first time

Posted: Sun Jan 18, 2009 4:21 pm
by jmut
You should use cronjob to regularly execute a script. This script will check in db some table(spool) with what's left to be done. What is in the spool is up to you.in this case it will store all mails that are to be sent. So the script will fetch the mail (body,text,to,from whatever... ) and try to send it...if successfull it will flag it as sent (so that next time the cronjob execute this script it doesn't send same mail again) and so on.

Re: How to send messages witch are not send the first time

Posted: Mon Jan 19, 2009 10:31 pm
by Chris Corbyn
Spooling will be added to Swift Mailer v4. Either ~arborint or myself will be adding this.

Note that v4 is currently in beta (see thread at the top of this forum).

Re: How to send messages witch are not send the first time

Posted: Tue Jan 20, 2009 12:17 pm
by brandweerman
Chris Corbyn wrote:Spooling will be added to Swift Mailer v4. Either ~arborint or myself will be adding this.

Note that v4 is currently in beta (see thread at the top of this forum).
Is the spooling optie also in the beta?

If not i will wait till v4 is out...

Any idea when this will be?

Re: How to send messages witch are not send the first time

Posted: Tue Jan 20, 2009 4:43 pm
by Chris Corbyn
Feb 21st is the deadline for public release. Spooling is not in there at the moment since it was only proposed recently ;)