What the best way to implementation email sending? - php

I have web application, and I want to implementation email system. My web application is a social network: users receive email when users update status and any another user is commented to their status.
What is the best way to implement that? I have been implement email system after users is comment, then in the same time I'm sending email to their user. The second option to use a schedule to send email.
I am using PHP and SwiftMailer.
To clarify: should I directly sent email to users, or should I use a database to queue mail and send via cron?

Please try phpmailer library functions

You could also try PostageApp.
http://postageapp.com/

You can use inbuilt php function .Please visit the following link.
http://php.net/manual/en/function.mail.php

My advice is to use a mailing service with an API, such as Sendgrid for large amounts of mails (>100 per day), and otherwise just use your php mailer of choice.
Sending mail via your own server has a couple of disadvantages, mainly related to getting blacklisted or marked as spam. This is because the other mail servers don't really know yours, and if suddenly a lot of mails start appearing, you look like a spambot.
To avoid sending a lot of mails at once, you also have to somehow queue the sending via batches, and for that you need cron jobs and such. Getting un-blacklisted is also not very easy, and simple domain changes will probably get you re-identified
Mailing services do relieve you of most of these problems, and are overall reasonably cheap. Learning the pitfalls of in-house mail solutions is usually too much for a single project, since it is a reasonably large topic.
Disclaimer: I do not work for any mail-sending service, I just happen to work in a place that had their domain blacklisted recently because of bad emailing practices.

Related

php mail() often not reaching the address

this is my problem, essentially - I set up a wordpress contact.php template that would submit forms and send it to my gmail. However, the issue is that it reaches the email only less than half of the time, and it's imperative that I get the rest of the emails.
The next issue related to this is that I did not set up a file that would log the sent out messages. MY question is, basically, - is it possible in any way to retrieve the sent emails that haven't been logged? is there usually a cache of emails maintained by the hosting provider? The only information I have is the IP addresses, and that is hardly any help in this situation.
Thank you.
Probably being hit by your spam filter. PHP's mail() function is prone to this because the mail is sent from the web server, which isn't generally configured with SPL, etc, that receiving mail systems look for to help them filter out spam.
I don't think I can answer the question of how to retrieve lost messages that have already been sent -- only your hosting provider can really help you with that, but my guess would be that they can't help. They are very unlikely to keep hold of outbound emails any longer than necessary. If you're lucky, they might have logs of email events, but even that might not have any useful data in it for you.
One question though: Have you checked your gmail spam box? I'm not a gmail user, but most mail systems do keep a spam box with filtered messages, so that users can retrieve an email that gets marked as spam incorrectly. I'd be surprised if gmail doesn't allow that, and if that's where your mail has gone, then problem solved.
For the future, I suggest switching to use a decent third party library for your mail such as phpMailer.
The advantage of phpMailer for you in particular is that it can be configured to send mail via gmail, which means you can send it to yourself from own account. This should be pretty much bullet proof as far as spam filtering is concerned. It should also be delivered quicker, since the mail will go direct to Google's servers, without needing to bounce around the internet first.
phpMailer will also make your mail code much cleaner than using the raw mail() function, and it allows more advanced features like attachments, without having to write mountains of code.
Hope that helps.

Emailing content to a php script

I am about to start a project that requires an email to be somehow ran through a PHP script. I have full control of the server that the email will be sent to and wondered if people could give me some thoughts or pointers as to the most elegant way parsing it with PHP. I am not editing the email and then forwarding it on.
The server is CentOS with Exim email.
Thanks in advance.
You implement a client for the mail box (php imap modules can work with pop3, imap4 and local mailboxes). You poll the mailbox for new arrived messages, retrieve new ones and parse it. All using the php imap module.
One of the best examples of this comes with Wordpress... there is a file wp-mail.php which is set up as a cron task to retrieve and parse emails... I have hacked it up several times to do such things!
To make life easier for you, rather that stress yourself with parsing emails (if you don't mind the cost) you could decide to use Postmark
I've been using their services for quite some time and i love them. They have an Incoming email API service now. Enough talk, simply check it out because I believe it will help with what you're trying to do.
There are three main approaches to this:
Run a cron task to poll an IMAP/Pop3 server every x minutes
Make exim run a script whenever it receives an email
Use a third party service to receive the email and send it on to your site.
I wrote a Blog Post detailing the options, although it's for Rails the main concept applies to any language including PHP.

Sending Notification Emails in PHP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Sending Bulk Emails using PHP
Is there a service out there that can handle sending emails constantly through PHP without issue? We're looking to send out 500+ emails a day or more and are worried about using the built in mail functions of PHP.
Any suggestions?
There's nothing inherently wrong with the built-in mail functions, and 500 e-mails a day is almost no load at all. PHP simply executes your configured MTA executable, such as sendmail.
However, I'd recommend using a better mail API such as Swiftmailer. This will enable you to build e-mails with HTML, attachments, and such much easier than trying to generate your own MIME messages.
For larger mail volumes, I would recommend using a 3rd party, such as MailChimp (or one of the many, many others). They're very good at keeping you off blacklists for spam and such.
500 emails/day really isn't that many. You have several options:
Send the mail yourself, from your server. You could use third party libraries to handle the multitude of options. Swiftmailer, PHPMailer etc or roll your own. Sending from your own servers, you will need to manage reverse DNS, SPF records etc and (assuming you're on Linux) will become quite well acquainted with Postfix et al.
Optionally you can use third-party services, such as http://sendgrid.com/ or http://aws.amazon.com/ses/. These are essentially pay-as-you-go mail servers with nice simple APIs. This can help with a lot of the heavy lifting involved in maintaining reliable mail servers. This gets complicated when you're sending thousands of emails per day. Throttling, queueing, load balancing etc.
Another option, if you're doing eMarketing is to use a service such as Mailchimp or Campaign Monitor. These will do all proofing, sending, throttling and reporting for you for a one-time fee.
you can use php's mail() function without any issue. but most of the shared hosting servers do not allow you send large volume emails.. You can use third party SMTP for this..

PHP E-Mail Client - Overcoming slow send/receive

I have developed a CRM that is used with a marketing website similar to manta.com. The CRM has a built-in email client. Basically it matches names and emails to addresses on file, and if the email is from a customer it loads their account information next to the email.
The entire system works, but is in some cases slow. Because each "region" of the country is managed by a different company, the software connects to several different mail servers, all of which behave differently.
In some cases (mostly with godaddy servers) it takes a very long time to send an email. It also takes a long time to load the inbox if they have a lot of messages (500+), even if it is paged.
I am using pear Mail::Factory smtp to send, and the built in php imap functions to receive.
I am thinking for outgoing messages I will just store the emails into a db and then have a cron script send it out, then they can send their email and move on right away.
Does anyone have any ideas/concepts for handling large inboxes via IMAP and php? I will have no control over the mail servers themselves, but have full control over the server that the CRM is on.
I am not looking for code, just concepts if you have them.
It is Linux (ubuntu), apache, mysql, php. I can use Zend if needed.
It looks like a combination of caching the emails and using the imap_fetch_overview function which omits the body of the email. This seems to eliminate any issues with the lag. I can also use it to page the results so I am only loading a small number (25-50) at a time. Thanks for the help.

SMTP or PHP mail on VPS ( Or Physical Severs) - A Social Networking site

I am developing a social networking site. It has functionality like user registration, people exchanging messages and sending email notifications for people's actions (and many more).
Currently I use PHP's mail function to send mails and it is working fine. I already set up a VPS and hosted the application.
My question may be a dumb question. Do Facebook and other social networking sites use SMTP servers to send the notifications or only just any kind of PHP mail function?
I read somewhere that using PHP's mail, there is a chance of mail going to SPAM folder. They advised using a certified SMTP server.
So, if I have to use an SMTP server:
1) Do I have to purchase a certified SMTP server separately? Or can this be hosted on same VPS whatever I have. If so, what server software will be good for this?
2) Are there settings I have to do in SMTP servers like send unlimited messages, because we don't know how many people exchange emails in a minute, and that is totally random.
To start: you are definitely going to have to use an SMTP server to send the emails from PHP. You can't simply throw your emails at the mail() function and expect it to work. You have to connect it to an SMTP server that does all of the dirty work.
However, if it's not your domain, I would suggest you don't do it. If you have the time to learn the ins and outs of email delivery and want to set up and maintain an SMTP server, by all means, go ahead.
If you'd rather focus on building your app and not worry about your emails getting delivered, I'd suggest an email delivery service. Here's a good list of services to check out:
PostageApp
Sendgrid
Postmark
Mailjet
And there are plenty more out there. All of them have a free option for you to play around with, so just look for the one that fits your needs and requirements.
(FULL DISCLOSURE: I am the Product Manager of PostageApp. Happy to answer any questions you might have about sending email from your app, though!)
The issue here is not really with the mail() function in itself, but in how you construct the emails. Messages can be treated as spam for a million and one reasons, but it is generally accepted that if you use one of the tried and tested mailer libraries, like Swiftmailer or PHPMailer (both free) there is marginally less chance of your messages being treated as spam.
Whether your messages get treated as spam is far more about how you construct your messages than how you send them. Another major factor is if your server sends thousands and thousands of emails all the time, so another hint is to be sparing with the emails you send out - only send them when you actually need to.
If you really want to know the answer to this question, you should do some reading on exactly how the modern email system works. Being able to build and send good emails is all about knowing how to work the system. Start here.

Categories