Jump to content

move from PHP 5.4 to PHP 5.6 breaks Contact Form


Recommended Posts

I have been using PS version 1.6.0.14 for years and need to continue using it.  I cannot and do not want to upgrade to a more recent version.

My webhost has finally prevented me from using PHP 5.4.xx on the server.  The lowest I can use is PHP 5.6.

This change in PHP on the server has broken the Contact Form.  The problem appears to be in ContactController.php, at this location:

else
{
	if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]',
		$var_list, $contact->email, $contact->name, $from, ($customer->id ? $customer->firstname.' '.$customer->lastname : ''),
				$file_attachment) ||
			!Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, $contact->email, $contact->name, $file_attachment))
				$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}

What is it about that code that is not compatible with PHP 5.6? 

Link to comment
Share on other sites

5 hours ago, endriu107 said:

Probably if you switch whole ContactController.php file from newest 1.6 version like 1.6.1.24 it should work.

@endriu107 thanks, I tried that, it didn't work.  I also replaced the class Mail.php with the newer Mail.php class from 1.6.1.24, because the problem seems to be within the Send function of the Mail class.  That also did not work.  So, there must be a variable or syntax or function call or something within the Send function (in the Mail.php class) that is not compatible with PHP 5.6.

Update: the problem is certainly with the Send function in the Mail.php class.  I went to Back Office > Advanced Parameters > Test Email Config > Send Test Email .. that feature also would not execute.  No message was returned on screen .. the "spinner" just kept spinning and spinning.

PHP on the server is not recording any PHP errors in the file "error_log" in any directories.  Is there a Prestashop log that might be recording the error?

I have been looking at the differences between PHP 5.4 and PHP 5.6 in this article (https://help.fasthosts.co.uk/app/answers/detail/a_id/2996/~/migrating-to-php-5.6-from-php-5.4), but have not discovered the incompatibility.  Other Classes and Tools are called from the Send function in the Mail.php class, so a deprecated syntax or method or something may exist in one of those other Classes or Tools.

Edited by finlander208 (see edit history)
Link to comment
Share on other sites

32 minutes ago, finlander208 said:

@endriu107 thanks, I tried that, it didn't work.  I also replaced the class Mail.php with the newer Mail.php class from 1.6.1.24, because the problem seems to be within the Send function of the Mail class.  That also did not work.  So, there must be a variable or syntax or function call or something within the Send function (in the Mail.php class) that is not compatible with PHP 5.6.

Check this one https://github.com/PrestaShop/PrestaShop-1.6/blob/master/controllers/front/ContactController.php

Link to comment
Share on other sites

1 minute ago, endriu107 said:

What exacly error you have?

I have not found a log file that contains an error message.  The error is simply that the Send function in the Mail class no longer works in PHP 5.6, so the Contact Form does not work and Send Test Email (in Advanced Parameters in PS Back Office) no longer works.

Link to comment
Share on other sites

5 minutes ago, ComGrafPL said:

thanks, I tried the newer 1.6 versions of ContactController.  The problem is in the Send function of the Mail.php class.  The Send function of the Mail.php class is apparently calling another Tool or Class (in PS version 1.6.0.14 on my site) that is incompatible with PHP 5.6.  

Link to comment
Share on other sites

On 2/26/2022 at 7:44 AM, endriu107 said:

Turn on debug mode and try use contact form if there is some errors they should appear on screen on submit this form.

Thanks, I turned on Debug mode (and cleared cache and forced template compilation), but no debug errors showed on screen when the problem occurred.  Only the same, standard red message: "An error occurred while sending the message.."

The problem must be in one of the function calls or tool calls in the Send function of the Mail class.  There must be something that is incompatible with PHP 5.6, when everything executes to send the mail from the contact form.

Link to comment
Share on other sites

2 minutes ago, endriu107 said:

Did you check email settings? Maybe you use invalid credentials? 

thanks, no, this problem has always occurred immediately after my webhost changed PHP on server from version 5.4 to 5.6, without me making any changes to back office configuration.  My webhost tried to move me to PHP 5.6 a couple of years ago, and this same problem happened, but I convinced them to put me back on PHP 5.4.  This time, they refuse to let me use 5.4.  The problem simply occurs when the Send function in Mail class tries to run on PHP 5.6.

Link to comment
Share on other sites

23 hours ago, endriu107 said:

Did you use SMTP settings or php mail() function? If you not use SMTP at first you should try use it because your server in this php version could have blocked mail() function.

hi, thanks, I have always used the SMTP method.  I will do some testing by replacing various function and tool code that is called from Mail class (Send function).  One-by-one, I might be able to find the code that is incompatible with PHP 5.6.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...