Email for social networkign site

Dear All,

I am developing a social networking site using Yii . It has components that send emails to the users


  1. user registration

  2. forgot password

  3. Users messages and comments notifications

  4. Weekly news letter

For the first three scenarios I used PHP mail function

mail('', 'My Subject', $message);

This is working fine . But the problem is the email content format and stuff is with controllers .

I am planing to move the email content and format to some component class with static variables holding the the email content .Similar to below one

class MyEmailTemplates


  public static const REGISTRATION=' This is email content for user registration ';



I am wondering is this the correct approach ? I am looking at YII Email , But that looks like need to have SMTP server . Do you recommend setting up SMTP server for my case to send emails?

and for the 4th one "Weekly news letter" Contains PDF generated news letter as attachment . Any scheduling mechanism we can use and also after sending email to thousand users just waiting for 2 minutes and sending again for the next thousand users ?

Thanks your help


Yii Fan

If you don’t use a certified SMTP server (DKIM/Domain Keys/SPF Records/RDNS) your email will bounce back and the php library sending the emails will be your least to worry about.

send email to many members need a lots of time (long-running php execution), you should consider using cron job to do that (periodic executing ) the console app yii 's Console Applications is to the purpose . the 3rd library for sending email like phpMailer and swiftMailer is powerful enough (and you can attach another file easily )

Thank You yiqing95 and twisted1919 for the information .

Sorry twisted1919 , I couldn’t understand the email bounce back … Do I have to use SMTP server ? Could you please throw some more light on this ? Sorry I am bad in mail servers and understanding them . Thank You

Here is the thing, if you don’t use a certified SMTP server, your host will send the emails (via php mailer, swift mailer or whatever + sendmail which is an email delivery daemon) BUT when these emails will reach the destination, the server receiving them will check if they are valid or not.

This is done by checking if your email has a valid DKIM/Domain Key signature, if your domain allows your email server to send email in behalf of it (this is done by checking the spf records and rdns)

If your email is not valid, that server will return it to the sender server, this will happen several times, then if the receiving server will keep receiving unwanted emails from you, in the end, it will blacklist your domain and every email will be returned back to you. This will be a real problem for you, because in the future, if you really use a certified email server, your domain is still blacklisted so you will need to do long communications to take your domain out from the blacklists.

Another thing if not using a SMTP server, when you send email via mail() func, if you have 100000 to send, they will all be send at once and beside maybe killing your server, when those emails are out, the receiver server will blacklist you for sure if you send such high number of emails at once, so you will have to implement a queue so that just, say 1000 emails are sent at once.

And why getting all that pain ? If you have a smtp server, you can send an unlimited number of emails at once, because if your SMTP server is correctly configuated, it will throttle the number of emails that go out at once and you will have no problem.The email servers have their own queue mechanism, which is way better than anyone could implement in php.

Now, for example, i have a dedicated server for one of my websites, that uses iRedMail (this is an email solution that basically transforms your server into a certified email server for linux OS), and even if i have DKIM/Domain keys/RDS/SPF and everything it needs to mark my emails as being valid, there are times when yahoo sends my emails back as being deferred(dunno the reason, yahoo is plain stupid sometimes)

So my advice(i went this road before, i know what a nightmare it is, how many nights i lost in front of the command line to make it work) to you, in case you want to start this in the right way, buy a VPS, a cheap one, say at 10$/mo and install iRedMail email solution on it, then use that server as your domain mail server, it will be a win in the long run, i guarantee.

If you buy a VPS, be sure to buy at least 5 ips that will rotate once at X sent emails.

Also, make sure you document yourself on this mail issue, is a black hole but you need to understand how everything works in order to win the situation.

Warning, advanced linux knowledge is required.

If you really need to send tens of thousands of emails, then maybe you should try a dedicated service?

I don’t know how to appreciate your answer . THANKS A LOT . I googled lot of times on this and puzzled which one to use . But now your explanation gave pretty good understanding what is happening behind the scenes

From my end I already having VPS ( managed hosting ) machine and running a social networking site ( specific to a community and not so much traffic now and not so famous yet ) .The site was developed using elgg ( social network framework) , But some how it slow for me and for my ideas it is not suited best . So writing every thing using YII framework . To deploy existing elgg site I took VPS ( Paying bit higher $69 per month,1280MB RAM ) and I never configured any SMTP server on it . So elgg is using normal PHP mail and sending emails to the people who gets registered , for forgot password and for the people email exchanges . In the email header we received from my site , it says "mailed-by:"

I will ask my hosting provider ( since it is managed hosting ) to setup SMTP server for me or I just checked it has all these services (imap,ping,pop3,http,smtp,dns,cpanel) , so may be it might have already installed SMTP server or something .

But again your reply freed me out of all my tension and going to use YII MAIL ( SMTP server …)

Thanks again


Yii Fan