sending email stored in DB

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
misch09
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 3:43 pm

sending email stored in DB

Post by misch09 »

Hi!

Today I started using swiftmailer with symfony and it looks very sexy; it's a Greate lib. But I have the following problem:

I am developing a webapp in symfony. And now I want to add a tell a friend form. My idea was to generate the email when the form is submitted and to safe it in the db.

In a cronjob I want to take the entry from the db and send it. Firstly I thought I can serialize the message object to put it in the db.
In the cronjob I wanted to unserialize the object, but this doesn't work.

Secondly I had the idea to store the mail source code retrieved from Swift_Message::toString() in the db. But now I see no way to send this source code. I see no way to give the finished mail source code to the Swift_Mailer object or to the Swift_Message object.

I want to store the finished email in the db because there are several places in my app which generate different mails. So I don't want to store the email fields(from, to, subject, ...) in the db.

Thankful for every hint,

misch
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: sending email stored in DB

Post by jackpf »

What?

Why don't you just send the email when they submit it?
misch09
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 3:43 pm

Re: sending email stored in DB

Post by misch09 »

1. it' slowing down the response time of the form.
2. What about error management.
3. It's bad softeare design to mix several tasks in one. The job of the form is to take the submitted values, check them and generate the response.
4. What happends if I want the emails to be processed when the server is less in use by site visitors(at night).
5. If you have five places where you generate emails. I am sure you don't want to have five places where mails are sent.

misch
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: sending email stored in DB

Post by jackpf »

I honestly doubt a few hundred people using a mailing script would slow down your server at all...unless you've got a site with millions using at the same time or something.

But I'm not entirely sure of your problem....you can't retrieve them from the database?
misch09
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 3:43 pm

Re: sending email stored in DB

Post by misch09 »

Hi!

On my local server the process of sending the mail directly in the form takes two seconds.

I found a solution:

In the script processing the form I build the message object. Here I can also embed images and so on.
To the model of the db entry which has a blob column to store the message, I mad a function putMessage().
In this function I take all parameters from the message object via getTo(), getFrom(), ... and put it in a hash.
This hash gets serialized and saved in the blob.

In my sending batch file I use the retrieveMessage function of this model to get back swift_message. In this function I unserialize the hash and put all values back in a message object. setTo(), ...

It's not the finest solution but it works.

misch
Post Reply