Jump to content

PHPMail stopped sending HTML-based emails


Go to solution Solved by vbcoach,

Recommended Posts

On 3/5/2022 at 9:13 PM, gizmola said:

Ok, let me clarify a few things for you.

  1. There is no such thing as phpmail.  You are introducing confusion thinking that such a thing exists.
  2. PHP has a mail() function, which is somewhat configurable via the php.ini.  By default it pipes mail input directly to whatever the local "Mail transfer agent" aka "MTA" is.  The MTA is operating system dependent, but it's some server process that implements Simple Mail Transfer Protocol (SMTP) which is the protocol mail *servers* use to send and receive emails.  Whether or not those emails actually get sent as expected or received, after mail has been called, has many complicated issues associated with it, and is the domain of experienced email system administrators.  In your case, that is entirely within the purview of Network Solutions.  I will offer just a few issues:
    1. To send email requires DNS, specifically MX records for a domain.
    2. In most cases systems are not sending email directly out of a specific application server.  They instead are using the hosting companies email servers. 
    3. To send email on behalf of a domain requires at very least SPF, and increasingly DKIM setups for the email servers on behalf of a domain
  3. The network solutions script is a red herring.  We need to see what your script is doing.  There are many ways to send email.  We also need to understand more about these emails you send.
    1. What is the from address?
    2. Is it from you at your domain?
    3. What do the headers look like for the test emails you can send out?
    4. Is NS proxying your emails for you?
    5. What code packages the "html" version
      1. THe RFC's for how emails work has specific requirements for what an email is supposed to look like.  An "html" email is not a replacement for a standard email.
        1. Technically an html email is just a attached version of the email that should be packaged with an original ascii only version.  Email clients then will retrieve the html version and display that.
        2. Many email systems are highly fault tolerant, and not unlike the way browsers will tolerate broken html and still display something for you in most cases, that doesn't mean you should or your software should ignore the standard and correct format for emails. 
          1. It is never correct to take code that would send an html email and then just add html tags to the body and send that instead, even if it has worked for you to some degree in the past. 
          2. Some email systems will reject that email outright and you will likely never know that they were rejected. 
          3. Some mail clients won't work or the email will look bad.  Viewing html emails is actually a choice for the email client.  Some people use clients that don't render html or they intentionally turn it off.  That might be the minority, but it is another reason to have a properly constructed email.

You really have a number of issues:

  • You have limited control of your hosted environment?
  • You aren't an expert on how email administration works or php
  • You're running a really old script on a version of php that has been End of life for a long time
  • You don't seem to have any test environment, so you're experimenting with your production environment, with limited visibility into that
  • Apparently your script has some bugs, but again we haven't seen it, or any portion of it.


To summarize.

  • Yes you should use PHP 7.4 (at minimum).  That is the *oldest* supported PHP version available.
  • You might very well be better served by using one of the many current supported PHP mail libraries rather than something as low level and hosting dependent as mail().  For example, many libraries actually implement SMTP themselves, and give you a lot more control over the process of sending emails programmatically, while at the same time insuring that the delivered email data is actually compliant with email standards
  • For any email sending you need a good handle on the questions I raised previously (how will you actually "send" email, in terms of what user@domain the email is coming from.  Is this from your domain, and if so, is the email setup for the domain valid and workable.  Anyone can setup something that "delivers" emails via smtp that will promptly be rejected or accepted and deleted with you never being the wiser.
  • The php Composer tool was released a decade ago.  There is no excuse left for a project that is not using composer to manage your dependencies.  This is also why you probably need a dev/test environment within which you can run composer.
    • Composer will download and manage your dependencies.
    • It will build a standards compliant autoloader for your application that you include so that class libraries like phpmailer can be properly autoloaded
  • Porting your email script is probably the path to getting something reliable and supported.

I hope this helps you start moving yourself in the right direction. If you want to start answering some of the questions I posed, and need help and advice in doing so, feel free to follow up.  Sending email seems simple but it has become a very complicated endeavor over the years, and like many things that seem simple on the surface, have a lot of hidden complexity to them, especially when things go wrong.

This was one of the most thoughtful, well written responses I have ever had on this forum in all the years that I have been on here.  You are spot-on in regards to my skill set, but I have had to learn everything on my own.  Thank you for your thoughtful (and not demeaning) response.

Link to comment
Share on other sites

Glad to have been of help.  Lately I've been doing quite a lot of email configuration and administration, that just reminds me how important all these different elements are for email delivery.  Being able to setup SPF records correctly, reverse DNS, DKIM (which also requires some substantial sysadmin configuration if running your own MTA) and topping it all off with DMARC, is a great reminder of how complicated email sending now is, especially if you don't want your emails rejected.  I was just debugging something that involved IP's on a couple of RBL lists due to spammers coming from a few hundred of over 100k ip's the hosting company controls.  What a nightmare!

Link to comment
Share on other sites

This also reminds me that I recently came across this channel, and he provides some of the best modern PHP topic tutorials I've seen.  Very lucid explanations and examples.  These might help you climb the mountain of stuff I brought up:

While there is mention of PHP8 for a lot of these, most if not all the material is relevant to 7.4 as well, and even earlier versions, although they are all pretty much end of life at this point.




I didn't watch this one, but it looks promising for the email topic:


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.