Page 1 of 1

Update database on every mail sent?

Posted: Fri Feb 29, 2008 5:08 pm
by rockafella
Hi,
I have around 5,000 members in my newsletter table. I wish to keep track of mails i.e. to whom mails have been sent and to whom not yet sent.

I am currently using batchsend method to send the mails, following is piece of the code:

Code: Select all

        // Fetch the subscribers
 
        $sql2 = mysql_query("SELECT email FROM subscribers WHERE unsubscribe != 'Y'");
        $recipients =& new Swift_RecipientList();   
 
        while ($row2 = mysql_fetch_row($sql2))
        {    
            $recipients->addTo("$row2[0]");
        }
        $swift = new Swift($smtp);
 
        $throttler->setEmailsPerMinute(100);
        $swift->attachPlugin($throttler, "throttler");
 
        $swift->batchSend($message, $recipients, new Swift_Address("xxx@xxx.com", "xxx"));
 
Any idea how to id update the database records in this situation?

Thanks in advance.

Re: Update database on every mail sent?

Posted: Thu Mar 06, 2008 2:38 pm
by francisjeffy
Hi,

One solution I could find for your scenario will be
->Store all the send email addresses to one array and the Non send items to another array.
->And the finally update the table with theses two arrays in two update queries

Further explanation of Solution
-> Send mail
-> Check mail send status
-> If mail send status is Success add the user record id to array mail_success
-> If mail send status is Fail add the user record id to array mail_fail
-> After all mail have been send to all users, Update the table with the user record id, mail status and send date and time

Considering the size of the mailing list it will be optimum to update table after all the mail have been send.

Kind Regards,

jeF

Re: Update database on every mail sent?

Posted: Thu Mar 06, 2008 2:47 pm
by rockafella
Hi,
Thanks for the input, currently what I have done is, running a cron job every 5 minute which will send mails in the batch of 250 and in the end I am updating all those 250 records using a single IN query. I think that did the job but now I have not much idea about the failed status thing.

I am currently using batchsend to send out mails, I am not sure how I will get the failed emails? (Also by failed you meant, bounced back or something? - any specific error code?)

Thanks

Re: Update database on every mail sent?

Posted: Fri Mar 07, 2008 7:57 am
by francisjeffy
Hi,

When you execute mail function, If the mail is sent correctly, the mail function will return a value '1' and if the mail was not sent it will return a value '0'. It has nothing to do with the email id being correct, if the parameters are passed correctly for the mail function and if SMTP is set correctly it will return 1. So if it returns '0' for a mail id, then it can be stored to send_fail array and can be resent later.

jeF

Re: Update database on every mail sent?

Posted: Fri Mar 07, 2008 8:00 am
by rockafella
But the only problem here is, i have batchsend running and it is running out of the loop, so I am not sure how it will throw the status for each mail separately..

Re: Update database on every mail sent?

Posted: Fri Mar 07, 2008 11:16 am
by YvesTan
You can try to modify Verbose plugin : http://swiftmailer.org/wikidocs/v3/plugins/verbose

Look the example on the bottom of this page ;)

Re: Update database on every mail sent?

Posted: Fri Mar 07, 2008 11:38 am
by rockafella
Thanks, i will check it out :)