How to send messages witch are not send the first time

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
brandweerman
Forum Newbie
Posts: 3
Joined: Wed Jan 14, 2009 3:09 pm

How to send messages witch are not send the first time

Post 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.';
 
 
 
 
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

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

Post 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.
brandweerman
Forum Newbie
Posts: 3
Joined: Wed Jan 14, 2009 3:09 pm

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

Post by brandweerman »

Wow,

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

Ideas are welcome...
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

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

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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).
brandweerman
Forum Newbie
Posts: 3
Joined: Wed Jan 14, 2009 3:09 pm

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

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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 ;)
Post Reply