Fast email delivery - php

I have a website that receives incoming emails via cloudmailin, adds the content to the database, and then sends a confirmation email back to the person who sent the email. Currently I'm using a php mail() function to send the reply, but it seems to take about 1.5 min to actually get to the user's inbox. Is there a way to make this more instantaneous? I'm currenly hosting the application on FatCow, and I'm sure it has to do with their mail server, but I don't really know much about how that works and am wondering if I have to change hosts to accomplish faster delivery times or if I can do anything about it without switching.

mail() is a black box. You're telling PHP to try sending a mail however the host has configured PHP to do so.
It's very likely that it's just calling sendmail in your case. It's also very likely that the mail queue on that machine isn't the fastest in the world. Shared hosting machines are often overloaded.
The very first thing you should do is ask your host about the mail delay. Perhaps something is wrong, and they can fix it. Or they might just tell you that a minute and a half is not a long time to wait.
There are lots of other options, mostly in the form of companies that provide an SMTP service to you. I can't recommend one, but I can recommend that you pop over to your favorite search engine and look for "smtp service." I've recently starting working with Amazon Simple Email Service. It's supposed to be fast and well-maintained, and it's certainly inexpensive.
All of those options are likely going to require some configuration changes on your end. For example, you'll want to set up custom DNS records (for DKIM and SPF) to ensure that mail from a third party provider isn't automatically flagged as spam.
Using SMTP with PHP is dead easy. There are plenty of mail generating options out there. My personal favorite is SwiftMailer. It even has a transport option for Amazon SES.
The final option, of course, is grabbing your own virtual private server or dedicated server, which will let you configure outgoing mail as you desire, at the cost of needing to know how to maintain that server.
Edit: Obligatory link to relevant Coding Horror post.

Related

Sending mail with PHP mail() on a Linode

I'm running a little Drupal site on a little Linode server. All I want is for Drupal to be able to send a little system email with an account login link (which uses PHP's mail() function). I don't want to receive mail, and I don't really care what the From email address is. Just a simple little login email.
From what I'm reading, this is just about the most difficult thing anyone could ever want to do... you have to follow opaque 1000-step guides and spend hours and days setting up an entire mail server.
Is it really that hard? I'm having trouble believing that it is. Linode has already unblocked the requisite ports for me. So, I repeat:
Is it really that hard? No one has ever done this without setting up a whole mail server (or paying for a third-party service)?

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.

Sending a large email mailout through Gmail or maybe even Google App Engine?

I have a client that I'm wanting to move to a virtual private server. I'm trying to keep his server as simple as possible, not even having an email server on there (or at least that is the plan). The reason being I've read that email servers are complex to setup and take up alot of resources. I'm not sure what to do here.
He has a newsletter that he sends out to almost 75,000 people. Currently on his shared hosting there is a cron job that calls a script that sends out a 100 emails at a time (to keep within the limits of the host). I'm curious to know if the same thing is possible to do but with using his his Google Apps email account? Effectively logging in and sending the email from there? I can't seem to contact Google about this and it doesn't seem to be in their help section.
Is it possible? Would it be wrong to do? My client has looked at many of the mail out things out there (MailChimp, etc) but they are very expensive for what they are. Especially as what he has now does work. Thing is, I'm implementing the whole thing new on a VPS and so am looking at options.
UPDATE: It seems that the Google option just isn't an option (I'm not surprised by this at all). May I ask which minimal email server could be set up on Ubuntu 10.04 LTS which would allow me to continue the cron approach I had before on the shared server that will allow sending the emails out? (I will still continue to use MX records to Google for the actual emails the client will be using)
UPDATE: A friend of mine went to a mini Django convension in London the other week and there was guy who runs Mixcloud. He said he uses Google App Engine to send emails, so it's totally scalable. There is Google App Engine code up on Github here: http://github.com/tow/appengine-mailer and this seems to make sending email very easy from Django, from a command-line (so could use with PHP) etc. Looks like a very good option and cheap too! What do you guys reckon?
UPDATE: I've started a new question to make it more refined and clear to hopefully help others who maybe having this problem: Effectively using Google App Engine to send lots of emails using PHP?
There is a limit of how many emails can be sent per day through the google apps accounts. The limit is waaay below 75k I think it is 2k per mailbox if he has the premier account.
Two options here. Sign up with a company that does this for him: Constant Contact, Mail Chimp, ...etc. Or install an SMTP server and have it go out how it did before. The performance hit the server will depend on what mail server you choose and how much load is being placed on it.
UPDATE: I primarily work with windows servers so my experience is there (setting up secure SMTP in windows is pretty easy). Googled around and found this page on Ubuntu's site. It has a bunch of options for doing this: https://help.ubuntu.com/community/MailServer . From that page you should only need the Mail Transfer Agent and possibly the Mailing Lists components. Also make sure to set up your SPF records correctly and identify this server's IP as an outgoing only server. It can also help to set up the server with an MX record with a priority higher than your other MX records. If google goes down incomming mail will try to go to your VPS but as long as you don't set it up to receive mail, just send it, it will bounce the request. Which would happen anyway if your google mail servers go down so nothing lost.
Lastly you can try to register your server's IP with yahoo as a bulk mailer.
UPDATE2: Also make sure to have the "FROM" address in the newsletter be a valid email address from a valid domain. This will help immensely with deliverability.
UPDATE3: Can you get a static IP with a APP Engine Account? If you can't get an IP (preferrably dedicated) assigned to you then your deliverability will be horrible and you will get blacklisted. IF you can get a static IP assigned to your App Engine account you can set it up in your SPF records and that solution should work.
I did this a while ago for a commercial website. To describe it as an utter ball-ache would be an understatement. The amount of man-hours we sent working with our mails, enabling the various headers to avoid it being flagged as spam, to ensure that it looked to ISPs as valid mail etc was far greater than anyone envisaged at the start of the project. Then there are issues with mail throttling and throughput - at one point we were sending a weekly mailout that took 8 days to go through the entire mailing list.....with obvious results.
Anyways, upshot is, outsource it - there are many companies out there who have already solved this problem for you - granted you have to pay for them, but its cheaper in the long run.
You should use a third party site to fulfill this clients requirements. There are lots of technical, legal, and spam issues that need to be overcome to ensure that your client is not blacklisted or fined.
A company like Industry Mailout, MailChimp, or Campaign Monitor will send your mail for you, and is often a lot cheaper than trying to do it all yourself. :D
Plus these companies offer useful analytics to make your campaign's better.

A couple problems re: CodeIgniter emailer

I have some problems with the email system for CodeIgniter:
First, the emails I send out (registration, confirmations) are getting caught in standard spam filters in gmail and other mail clients. How do I get around this? How do companies like Facebook get their emails through consistently?
Second, the mailer is working locally but once we deploy it it no longer runs (doesn't send emails) but all the other forms run just fine. Anyone ever run into a problem like this?
Thanks for all the help!
I can't really answer your first question - it's not specific to CodeIgniter. You just need to make sure your email doesn't look like spam. In short - there's no way of guaranteeing your e-mail will not end up in a spam filter.
As for the second question, I expect your production server needs to be configured properly for email. You probably need to configure CodeIgniter to send email properly. I would suggest setting up an SMTP server (or using an existing one) rather than using the standard PHP mail which I think CodeIgniter uses by default.
Regarding spam, most organisations are very secretive about how they prevent spam (not wanting to publish information which helps the spammers) and in some cases they don't actually know - an obvious examlpe of this is bayesian filtering - but, for example, hotmail use a completely unaccountable army of volunteers to manually classify emails.
Do and get a copy of spamassassin and try to reverse engineer how the standard rules work. Obvious things to check are:
1) AVOIDING LOTS OF CAPITALS
2) don't mention the 'V' word
3) make sure you've got a current and restrictive SPF 1.0 policy published
4) make sure your sending from an address which has A and PTR DNS records
5) Do provide a reply-to and from email address which use your domain in the address
the mailer is working locally but once we deploy it it no longer runs
doesn't send emails
Which? These are 2 totally seperate things. If the code is falling over (if so why have you not provided the error details) then its likely a PHP version issue or a problem with the connection to the MTA (or the PHP mail config).
The latter is a problem with the MTA itself.
99.9% of problems reported as PHP mail failures have nothing to do with PHP and are problems with the MTA.
Enabled detailled error reporting for your MTA and see where it is failing.
C.
You may have to configure the email on your server differently than your local development environment. I've had to in the past.
There are two basic ways that PHP can send mail:
Via a UNIX program called "sendmail" (only on non-Windows servers and only if it is installed - check with your hosting provider)
Via a SMTP server.
If you've configured CodeIgniter to use SENDMAIL, check to ensure that the Sendmail path is correct. Your hosting provider usually provides this somewhere in their online documentation.
If you're using SMTP, you need to make sure that your server can contact the SMTP server. You can do this by logging into the server via SSH and typing "telnet your.smtpserver.com 25". If you get an error message about not being able to connect, you know you have a problem with your hosting provider connecting to your mail server.
I've been able to diagnose this problem by enabling logging on my production server (http://bit.ly/4pprd6) and adding log_message('error', $this->email->print_debugger()) right after I attempt to send a message.

Is there a SMTP mail transfer library in PHP

I want to write an email transfer service and need a MTU replacement of sendmail/postfix.
I'm not looking how to deliver to a transmitting SMTP server (like a postfix listing on a SMTP port). I also don't need the receiving part of the server, bounces etc. would go to a different existing postfix.
All of it in pure PHP. SMTP is a pretty easy protocol but this would require access to the MX DNS record and other lot of details that need to be taken care of.
Why do i need this? Because most shared internet providers have insane low limits for sending out emails like 500 per day. Thats almost nothing if you want to setup even the lowest traffic email list.
EDIT: Please Note: The code needs to connect to the receivers SMTP server and deliver the message with an adapted header set (removed BCC list, added Path route). If you see a SMTP class less then 5000 lines or requires you to configure a SMTP hostip and port then this is not the stuff i'm looking for.
It needs to do all the stuff sendmail is doing just as a PHP library.
I use Pear's Mail class.
EDIT
After re-reading this, I see there's more to it than just a library. You are asking to send direct to the remote MX.
Why reinvent the wheel? Set up an instance of postfix on the server, which only listens to connections from the web server... and let an MTA do what it does best. Hand off the messages from php to a real mail server and move on.
In the case of ISP's that block outbound port 25 and force the use of a smarthost, this also allows you to restrict the rate of messages sent to the smarthost.
Lastly, sending straight to the end MX from your php script is a bad idea, because if you send to me, I'll never get it. I and many other sites use "greylisting" to reduce spam, which denies all initial requests with a 450 temporary error. Real MTA's will try again, but unless you implemented a delay queue and try again, your message will never go through.
We use http://sourceforge.net/projects/phpmailer/ to do SMTP email from PHP
SwiftMailer is the only library you'll need.
Try Zend Framework component Zend_Mail (you can use the component independently of the entire framework).
Here is something I wrote. It's quite minimal and I don't know how well it performs, but I wrote it with the intention of replacing sendmail, meaning that it will take a message, lookup all the MX records for the recipient domains, contact those mail servers and deliver a message for the corresponding recipients. It worked well enough for me at the time.
https://github.com/denvertimothy/ThriveSMTP
It's been a long time since I've used it, but I threw it up on Github just now.
I used http://www.mailerq.com/ which works cool. Its a queue based mail transfer agent. It requires rabbitmq.
It provides multiple worker as well.easy to store in database.
It provided management console as well.
worth to check it

Categories