0

This is not a coding issue, so I think "superuser" is the best place to post this.

I have been trying to send email using PHP for about 1 week now, and still no success. My story so far:

  1. Trying to contact my hosting company about the SMTP server/port to put in my "php.ini" to send mails. They answer I have an unmanaged dedicated server, which means basically either I pay for their extra services or go --- myself.

  2. Trying to use random PHP scripts I found on google, have no idea how they work but they always end up in Spam folders, and are very often even ignored by big mailing systems like hotmail (they don't even show up at all most of the times)

  3. I tried the PHPMailer class that uses Google's SMTP server, but for some reason, google freeze and blocks access to any gmail account I make, once I type its password on the PHP script. I can't use that account anymore.

  4. I have one option left now, hosting my own SMTP server ? But have no idea how and seems like a lot of work to do.. I probably need weeks to learn how that works befor deciding if it was a good idea or not.

Why is it so hard to send a simple "Hello World" email using PHP, for free ? What can you guys recommend me to solve this issue ? Should I try to host my own SMTP server ? (I have a static IP and a dot com domain)

2
  • You said your emails are ending up in spam folders - they're being sent. I don't think you're sending them from a legitimate domain, so it's probably trying to do something like [email protected], which would most likely be spam to all email clients.
    – cutrightjm
    Apr 12, 2013 at 1:06
  • detail blog here: goo.gl/O1zw89 Jun 22, 2015 at 11:29

2 Answers 2

3

Sending email via php is easy... I think your question is more about how to get emails delivered to your recipients...

Do some googling on "email deliverability" and check out this post:

https://stackoverflow.com/questions/4960582/help-registration-emails-go-to-spam-inbox

Also, using a reputable (paid) smtp service can help ... Sendgrid, socketlabs, authsmtp, etc. (I've used all 3)

3
  1. PHP scripts do not necessarily need an SMTP server to send mail. You can even send an email "by hand" from the command line. SMTP was specifically designed for this.

  2. An email can end up in spam folders for a number of reasons which can be more or less divided into two categories:

    Filtering based on the email itself

    A "trustworthy" email will have a subject, proper headers, be multipart mails rather than HTML-only, contain a minimum amount of text and avoid large images and some trigger words. The exact details depend on the spam filter's configuration.

    This will partially depend on the PHP script.

    Filtering based on the host

    When receiving incoming mail, many spam filters check if the IP (or the hostname or the sender domain) is blacklisted (check here) or whitelisted (apply, e.g., here) on some real-time list, if the host is allowed to send emails from that domain (SPF) and if the specific server is allowed to do so (DKIM).

  3. There's a recent tutorial here on how to do this.

    The line

    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    

    seems particularly important, since it's not a part of most PHPMailer tutorials and failure to use SSL could be a reason for blocking a Google account.

  4. If you host an SMTP server on the same machine that's sending the mails via PHP, you'll have exactly the same problems.

Why is it so hard to send a simple "Hello World" email using PHP, for free ?

Spam. Lots of it. According to Trustwave's Spam Statistics, almost three out of every four emails are spam. This requires rather aggressive filtering to prevent all of us from getting drowned in spam.

Not the answer you're looking for? Browse other questions tagged .