Jump to content

PHPMail stopped sending HTML-based emails


Go to solution Solved by vbcoach,

Recommended Posts

Hello all. Need assistance on something I think should be a simple fix . I am using a PHP Mailer app on my website hosting, which is Network Solutions, I know, shame on me. Very recently Network Solutions stopped sending my HTML-encoded emails for some unknown odd reason. Using their PHP mail testing application, those emails with non-HTML are working and sending just fine, but as soon as I try to send one with HTML(isHTML=True) encoding, it never sends, but I also don't get an error. The program tells me the email was sent successfully.

Can anyone help me out here? 

Link to comment
Share on other sites

As you may already know, I do not have rights to edit the php.ini code as it is on a shared hosting site, but I will try your suggestion to add these two lines of code and see how the site reacts to it.  I am using the pretty much standard PHPMail script.  This script has served me well for the past 7-8 years or so and was working quite fine, actually.  That is up until November of last year.  The script still works, but only without HTML.  Don't know if NetSol suddenly requires SMTP Auth now or what?  Let me see what happens with your suggested changes...

Link to comment
Share on other sites

I didn't make any suggestions.  Just wanted to know what you may have done to resolve this.  Have you in fact made any changes since Nov. that may be unknowingly the cause of your problem?  If not your fault, have you contacted Tech Support at your host to ask them?  Sometimes when my host does an upgrade they leave out some settings in the ini file that cause me problems until I remind them that they left something out.

Edited by ginerjm
Link to comment
Share on other sites

Yes for the past two days I have contacted numerous people over at Network Solutions, and all they want to do is send me over to their paid support a.k.a. "MyTime Support".  My code hasn't changed a bit, but I am sure Network Solutions did some upgrades they didn't tell me about.

Link to comment
Share on other sites

I would change hosts.  My provider is very good at resolving these kinds of issues when the problem could be their doing.  

You said that you are able to check the is html setting and confirm that you have it set or are setting it as you prep your message?

Link to comment
Share on other sites

Yes, the isHTML(true) is part of the PHPMail script and my test-mail script.  Only difference is that the test script has a checkbox to enable sending of mail using HTML.  That's when it stops sending.

Link to comment
Share on other sites

I was saying that I was using two scripts.  It's the Network Solution test-email.php script that has the HTML checkbox option.  The PHPMail script I use to send the team receipt page emails already has HTML enabled.  The script returns a message that the email is being sent as usual, but nothing is received via email.

Link to comment
Share on other sites

You are saying that the script (yours) you run on your host has an option and you are sure that you are handling the checkbox correctly?

And that some other script that you run somehow  does not have a checkbox but does have HTML turned on and it does or doesn't work?

I am getting confused and this is getting frustrating.

Link to comment
Share on other sites

Let's take the confusion out of this, shall we?

For years and years and years, I have been using the PHPMail script on github.  Been working sending html emails for 7-8 years now without issue.  It stopped sending last November.  Something changed at NetSol and I don't know what it might be?  Some security issue most likely?


Network Solutions placed a test php mail script in my root folder years ago for testing.  It was created by NetSol for NetSol accounts for testing purposes.  That test script has various small options like using PHP Mail() or PEAR module, and also has a checkbox to enable sending as HTML.  This script verified that PHPMail() is working.  With HTML unchecked, the test email sends just fine, and I receive a message stating that the email has been sent successfully.  With the HTML box checked?  Same response, message sent successfully, but no HTML email is ever received.

Hope this clears things up?

What have I done?  Remember, nothing in the original PHPMail script (or website) has been changed at all regarding the PHPMail module.  In the TEST script, I tried auth-true and entered the un & pw, and still no HTML mail is ever received.  This is why I came here.  Why is HTML mail suddenly being blocked?

Link to comment
Share on other sites

So  - a script that NS wrote 'years ago' and put onto your domain works when they run it (?) but not when you run it?  That makes no sense. And why did they write this 'years ago'?  I thought you were working fine up til Nov.?

Edited by ginerjm
Link to comment
Share on other sites

Wow!  We are just not on the same page here!  The NS script is only a "test script" to verify that the PHP Mail() service is working.  It send out a test email given the options you enter.  If I "UNCHECK" the send using HTML box, the test script sends out a 'test' email properly and returns a message saying the email was sent successfully.  If I "CHECK" the use HTML box, I still get the same message that the email was sent successfully, but no email is received.  NetSol is obvioulsy blocking HTML emails from being sent somehow.  I just can't figure out what they did on the backend to block HTML emails.

Link to comment
Share on other sites

Well what I did was to upgrade php from v5.6 to v7.4 and now nothing works, except for better error messages.

  <title>PHP Form Mail Test Script</title>
<h3>PHP Form Mail Test Script</h3>
	$email = $_REQUEST['email'];
	$body = $_REQUEST['body'];
	$subject = $_REQUEST['subject'];
	$from = $_REQUEST['from'];
	$sendusing = $_REQUEST['sendusing'];
	$usehtml = $_REQUEST['usehtml'];

	if ($sendusing == "mail") {
		$header = "From: " . $from . "\n";
		if ($usehtml == "yes") $header .= "Content-Type:text/html\n"; else $header .= "Content-Type:text/plain\n";
		if (mail($email, $subject, $body, $header))  echo "SUCCESS... Email sent using Mail() function";else  echo "FAILED TO SEND!";
		echo "<br>" . date('l dS \of F Y h:i:s A') . "<br><br>";
	} else if ($sendusing == "pear") {
		if (mail_this($email, $subject, $body, $from))  echo "SUCCESS... Email sent to using PEAR module";else  echo "FAILED TO SEND!";
		echo "<br>" . date('l dS \of F Y h:i:s A') . "<br><br>";
	} else {
		$email = "Type Email Address";
		$body = "FormMail Test";
		$subject = "Test Email";
		$from = "custserv@networksolutions.com";
		$sendusing = "mail";

<table><form method="post" action="" name="sendmailtest">
	<tr><td>TO:</td><td><input value="<?PHP echo $email;?>" name="email" size="35"></td></tr>
	<tr><td>FROM:</td><td><input value="<?PHP echo $from;?>" name="from" size="35"></td></tr>
    <tr><td>Subject:</td><td><input value="<?PHP echo $subject;?>" name="subject" size="35"></td></tr>
	<tr><td colspan=2>Body:<br><textarea  cols="45" rows="3" name="body"><?PHP echo $body;?></textarea></tr>
	<tr><td>Send Using:</td>
	<td><input name='sendusing' value='mail' type='radio'<?PHP if ($sendusing == "mail") echo " checked='checked'";?>><b>Mail() Function</b><br>
	<input name='sendusing' value='pear' type='radio'<?PHP if ($sendusing == "pear") echo " checked='checked'";?>><b>PEAR Module</b></td></tr>
	<tr><td>Use HTML <input name="usehtml" value="yes" type="checkbox"<?PHP if ($usehtml == "yes") echo " checked='checked'";?>></td>
	<td align=right><input name="submit" value="Send Email" type="submit"></td></tr>

function mail_this($email, $subject, $body, $from) {

	$headers['From']    = $from;
	$headers['To']      = $email;
	$headers['Subject'] = $subject;
	if ($usehtml == "yes") $headers['Content-type'] = "text/html"; else $headers['Content-type'] = "text/plain";

	$params["host"] = "localhost";
	$params["port"] = "25";
	$params["auth"] = false;
	$params["username"] = "username";
	$params["password"] = "password";

	// Create the mail object using the Mail::factory method
	$mail_object =& Mail::factory('smtp', $params);

	$mail_object->send($email, $headers, $body);

	if (PEAR::isError($mail_object)) {
  		return false;
 	} else {
  		return true;
##                                                   ##
## NOTE:  This is a Network Solutions Test Script.   ##
## Any modifications to this script are not the      ##
## responsibility of Network Solutions as this script## 
## was generated only to ensure that your service is ##
## functioning properly.                             ##
##                                                   ##


Anyone else care to take a stab at this?


Thanks for trying Ginerjm

Link to comment
Share on other sites

Also, what I would like to do now since I have upgraded the PHP to v7.4 is to try the newer PHPMailer v5.6 or v6.x - but I am running a Windows website on NetSol shared hosting platform, so I do not have backend or command-line access like I do on a linux system.  When I look at the PHPMailer code, I do not see files from the documentation like the PHPautoloader.php for example, nor do I see a folder called vendor anywhere?  IU am kind of stumped at this point and really need some help with this ASAP!


Link to comment
Share on other sites

So PHP 7.4 threw too many errors on my site, so I dropped down to PHP 7.0  Took care of  other issues, but now on the test PHPMail script getting this error - I think it has something to do with the headers not being recognized?

Warning: mail(): SMTP server response: 553 5.0.0 <custserv@networksolutions.com... Unbalanced '<' 500 5.5.1 Command unrecognized: "Content-Type:text/html>" in \\WDP\DFS\30\1\9\6\3007726691\user\sites\xxxxxx.site\www\mailer.php on line 19

Any thoughts?  Anyone?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • Solution

For anyone who might be reading this using the Network Solutions Shared Hosting platform, the ultimate fix was the mail server security was changed last November and required SSL/TLS now, even though they did not update their own documentation.  Even their own technicians were not aware of this.  The ultimate fix was upgrading PHPMailer to v6.6.0 and changing the port to 587 with TLS (on localhost)

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.