Update database on every mail sent?

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
rockafella
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 10:43 am

Update database on every mail sent?

Post 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.
francisjeffy
Forum Newbie
Posts: 17
Joined: Fri Feb 29, 2008 12:10 pm

Re: Update database on every mail sent?

Post 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
rockafella
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 10:43 am

Re: Update database on every mail sent?

Post 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
francisjeffy
Forum Newbie
Posts: 17
Joined: Fri Feb 29, 2008 12:10 pm

Re: Update database on every mail sent?

Post 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
rockafella
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 10:43 am

Re: Update database on every mail sent?

Post 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..
YvesTan
Forum Newbie
Posts: 8
Joined: Thu Mar 06, 2008 1:54 pm

Re: Update database on every mail sent?

Post 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 ;)
rockafella
Forum Newbie
Posts: 6
Joined: Mon Feb 04, 2008 10:43 am

Re: Update database on every mail sent?

Post by rockafella »

Thanks, i will check it out :)
Post Reply