Sending mail with PHP mail() on a Linode - php

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)?

Related

Service which presents your outgoing email as a draft email when testing on localhost?

Lots of answers here and elsewhere on Google for how to setup your WAMP or XAMP on localhost to send emails.
However for testing/developing, you mostly don't care about emails actually getting transmitted. You just want to check how they're formed, and whether the email picked up the correct settings and options.
So, I remember having this problem a few months ago and finding a solution/service which did this:
As soon as my PHP code triggered an outgoing email, it would present it as a real draft email in a new window in my email client (Outlook, as it happens). I could check the from/to/subject/body instantly and easily. Nothing actually got transmitted, and I didn't have to keep a bunch of inboxes open somewhere or worry about delays or junk folders.
Trouble is I can't remember how I set this thing up. It was either a service which I downloaded and installed or it was a tutorial on how to set this up in WAMP. It was possibly a WordPress plugin but I'm not sure. I am certain it was free.
Does anyone recognise this kind of setup for email testing in PHP?
Are you sure it is a PHP configuration and not a software?
I used a mail smtp 'catcher' that works as you describe.
I hope it could be useful for your interests: Test Mail Server Tool (http://www.toolheap.com/test-mail-server-tool/)
I'll be accepting Nacho's answer. For completeness ... following StackOverflow's Related questions and checking out some other answers, I see there's also a service called Papercut mentioned here, which I might also check out.

Can PHP offer accurate sent mail reports?

I´m using Drupal (PHP) and sometimes I use it to send email to some of my registered users (ie. using a contact form located inside their profile). This is very common in every CMS, PHP forum, etc.
The thing is that Drupal usually prints out a successful message when the email was sent, and not always the email is actually sent.
On the other hand, my hosting uses VHM panel with VPS servers.
From their control panel I can check all mail that goes from my server to the outside. In VHM it´s called "Mail Delivery Reports". That´s accurate enough, and I think most VPS control panel probably have some similar utility.
My question is: When Drupal tells me that the email has been sent, and I go to the Mail Delivery report on my hosting control panel, and it says that it has not been sent. Is that a PHP flaw?
Is there a way to get accurate reports within PHP?
Please excuse my grammar. It has been kinda difficult for me to actually get myself clear on what I mean in english.
UPDATE:
I´m not asking if the user reads the email, not even if it later on gets bounced, just to know if PHP has some accurate way to report if the email was sent.
I know there are some services offering that, but I´m just asking about PHP capabilities (and if that´s actually possible).
PHP responsibility is to give it to your specified transport method. (sendmail, smtp etc.) and tell you if the transport accepted it or not.
If you use sendmail (or postfix) what php tells you is that it has been queued for sending and nothing else. PHP doesn't know if it will be sent or not. unless you parse the queues and try to go from there.
No. It is impossible for PHP to track sent emails. That is not, never has been, and never will be, PHP's job.
PHP simply generates the email (e.g. builds the html) and then hands it over to a mail transfer agent. e.g. your local sendmail.
In a real-world equivalent, PHP is you walking an envelope down to the street corner and dropping it into the mailbox. If the letter disappears down the chute, PHP will report success. After that, actual DELIVERY of the mail is entirely out of PHP's hands.
Maybe the mailbox gets flattened by a drunk driver, maybe the pickup truck gets into a firey crash, maybe the postal sorting facility gets hit by a meteor, etc...
None of that is PHP's problem, and undetectable by PHP anyways. It walked down the street, it saw the letter disappear down the slots. Mission accomplished.
At best you could set the "return service requested" mail headers, which 99.99% of people will probably ignore or disallow, or embed a web-bug inside the email and hope that the recipient's mail client will actually load the bug.

PHP mail / PEAR mail

On my directory website I have a "send email" functionality. This lets a user submit an enquiry to a company. A copy of this enquiry is also sent to my inbox.
A few months ago I noticed that I had stopped receiving the email copy to my inbox. So I investigated this and it turned out that my web host was no longer allowing sending external emails using the PHP mail function.
When I questioned this I was told that I would need to start using a third party mail plugin, and I was recommended to use PEAR.
So I converted my PHP script to use PEAR and managed to get it working on my site. All was good until until one day I thought it would be a good idead to switch to PHP 5.3 on my web host. A few days later I noticed that I had again stopped receiving the email copy to my inbox.
So again I investigated this and found that it was broken. I was told that I would need to revert back to PHP 5.2 for this to work. So basically that's what I had to do to make it work again.
My question is, how can I know when the mail functionality is broken as soon as it breaks? During the time it takes for me to realise it's broken, several enquiries could be being sent from the site which aren't actually going anywhere.
And secondly should I stick with PEAR or are there any better alternatives out there?
There are a number of alternatives to PEAR::Mail. However first I have to address the question of whether your goal is to pay your hosting company so that they arbitrarily break your site and subsequently, your business? I'm not sure why anyone would pay to be on a habitrail wheel of fail, and pay for that.
With that said this package http://swiftmailer.org/ has become very popular and is bundled as part of the symfony2 framework, which is an excellent endorsement of its functionality and support for the latest/greatest features in PHP.
Prior to that, http://phpmailer.worxware.com/ was a very popular package.
As for detecting whether your mail is working, the only way to do that is to have an automated test job that sends you an email every day, or at whatever periodicity you want. If you don't get that email, you know that there is an issue that requires investigation.

Fast email delivery

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.

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.

Categories