Email notificiation on different actions - php

I'm creating email notification system on my site to send email to the users who has subscribed the article for new comments... I would like to know what is the best way to handle with this situation in php. Should I use the mail function just after the database insertion or there is some better ways. Will it slow down the process of adding new comments if there are too many subscribers?

I would create a new database table and add the subscribers that needs notifications to that table. Then run a crontab every 5 minutes that sends the emails to those whose article has been commented. That way you don't have to send it directly thus clogging the user experience with longer loading times.

You can send an email as soon as a comment is inserted into the database or when admin/mod approves from admin side if you such mechanism.
Will it slow down the process of
adding new comments if there are too
many subscribers?
It will because you will be sending the email to more and more subscribers. However, you might want to consider optimizing your insertion query as well as your code if you can.

Related

How to manage newsletters?

I have developed newsletter module for a single user and its works fine.
Now I need to expand the module for multiple users.
My question is that, how can I manage the newsletters when more than one user schedule newsletters for multiple subscribers at the same time?
I have thought it for 2 ways, First is execute 1st newsletter after it finished send 2nd. Second way is fetch random records for subscribers from database to send the newsletter so it will send it simultaneously.
I would recommend you to store all tasks in the database and function that sends all mails and mark the tasks as done. This function I would execute using a cronjob.
https://ellislab.com/codeigniter/user-guide/general/cli.html
I would also recommend you to send the mails one by one (depending on how many you have to send) to avoid to become marked as spam.

WordPress plugin with e-mail mass sending

I'm currently making a promotion plugin for WordPress where I need to send out e-mails to different press e-mails based on a checkbox-list. My hosting provider has a limit of 200 e-mails/hour, but I don't think I will reach that limit. I know that mailing list providers are recommended, but my plugin has some functions (like making promo codes etc.). Everything is now finished with the plugin, and I only need the function for sending.
I have been searching for solutions, and have been looking at timers in PHP to avoid spam detection. I think I will end up with Cron jobs. I have looked into the built in WordPress cron job function, and will try to use this one.
I have never been using cron jobs before, so my questions is: how can I keep track on which e-mail my plugin has sent to? Do I need a temp table where each row is deleted when sent?
Any other suggestions for my solution would be appreciated!
if(mail(//params))
{
//insert this email id in db
}
you can keep track by inserting email id in to db if email sent successfully.

How to realize a Newsletter system with Rss news feed?

I have a news portal with everyday news. My need is to send through newsletter the daily news to subscribers.
I've already realized a PHP/MySQL custom newsletter system that performs the following tasks:
fetches the daily news
fetches the list of users who want the newsletter
everynight through a cronjob I launch a script that performs the above every 5 minutes sending the newsletter to 10 recipients at a time each cycle
Problems:
I have to estimate how long this cronjob needs to run in order to complete the full list of users (5' x 10 emails) = 120Email/hours = TotalUsers/emailperhours = number of hours the cronjob needs to run
I overcome this problem because I don't have so much users until now and I can still manage to make the cronjob run enough to send all mails, but for the future?
All email receievers are saved double opt-in, means I'm quite sure of their existence, but it happens how you can imagine that I'll have anyway many Mail delivery for other reasons:
here I need help because I dunno how to catch there Mail delivery through PHP and update MySQL tables in order to suspend these unnnecessary sendings.
Alternatives:
I know that there are many providers who offer Newsletter systems but this works fine every time u go and compile your static email body. Here I need a dynamic email body to be generated every day with fresh news and then send it to recipients.
Still here I need some advice.
You might find it worthwhile using a service like SendGrid - they have an API that handles dynamic content. I haven't tested it out that aspect myself, but for the small price they charge it might be worth saving you the headache.

Can I have a user database synced with SugarCRM and use it mostly for emailing?

I work for a company that has a website with about 700,000 users, it would need a tool that would:
List all users
Email users, create templates, send a newsletter
Show products a user has purchased
If you find a user, show which emails have been sent to the user
Create automated tasks, example: send an email to every user that has a product expiring in 30 days
I'm not sure a CRM can do all theses things, I wanted to try a CRM to figure out how close can I get to having a tool that can do all this. I read that SugarCRM is pretty good, and its free so I'm going to try it out.
What I wanted to know is, using the REST or SOAP api of SugarCRM, can I synchronise all my users with the SugarCRM database ? Or for example each time a user is created on our website, insert it in the database.
And then each time we send an email with our website, use SugarCRM instead to send a mail, and store the data. So that we can view which emails have been sent to specific users.
Thank you
Yes you can do all that but it may require some customisation to suit it exactly to your needs. By 'users' I assume you are referring to Customer 'Accounts' as known on the SugarCRM?
Add custom fields to the Contacts module using Studio. The easiest and quickest way to get your data in will be directly to the database.
The standard fields in Sugar Contacts go in the contacts table. Your custom fields will have "_c" appended to their names and be created in the contacts_cstm table. The two tables are related by contacts.id = contacts_cstm.id_c, which is generally a GUID field (but can be any string value if you need it to be).
Then you need to have a process to add new users in your website into sugar. I suggest polling your user db periodically to look for new records and using the SOAP/REST API (good luck though, it's fairly horrible) to insert them into Sugar.
Other than that your use case is pretty much standard Sugar. For automated tasks which happen whenever an email is sent/received or when a new contact is created, you'll want to look at logic hooks, search for logic_hooks.php in the Sugar documentation.

How shall I setup user event notifications in my code?

I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.

Categories