Php mail script upgrade

Jacques Laurence
Jacques Laurence used Ask the Experts™
on
This is a php script, which basically does the send mail function via terminal shell, I am studying it and the curious thing is that it worked in my tests only in the Ubuntu 14.04 versions with php5 and postfix. But I could not get it to work on Ubuntu 18.04 or Debian 9. I would like to ask for help to change the code in order to make it work in those versions. Thank you.

javali.php
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
Where is the script?

Author

Commented:
The php file is attached
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
But I could not get it to work on Ubuntu 18.04 or Debian 9

Is there any error message or any output? We need to know what you mean by could not get it to work.

Do you get any output from echo statements?
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Author

Commented:
Can you take a practical test? Do you have any 18.04 ubuntu server or debian 9 server?
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
Unfortunately, I don't have anyone from them that why I'm trying to know from you what happens exactly when you execute the PHP script.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Have you considered migrating the script to use PHPMailer (https://github.com/PHPMailer/PHPMailer)

It takes a lot of the hassle out of sending emails from PHP.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
What SMTP email server (like Postfix) is installed on the other systems?  You can't send email without a SMTP server.

Author

Commented:
The interesting thing is to make it work in other distros just like it works on ubuntu 14.04. The idea is to make the script work on Ubuntu 18.04 as well. Works on ubuntu 14.04 with Postfix
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
SMTP servers which are required for the PHP mail() function to work are NOT automatically installed on the LInux systems I have.  I had to do the install myself.

Author

Commented:
In the description I explained that it is installed and works on ubuntu 14.04, the point is that even with everything installed and configured correctly it does not work in the most current versions of ubuntu (16.04, 18.04)
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
Then you need to debug your code to know where exactly the script stops, it does not work doesn't help us so much to identify the problem source, share with us the output of your script, screenshots, anything could help us to help you...

Author

Commented:
the problem is that it does not generate any error or log message
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
SMTP program requirements.
http://php.net/manual/en/mail.requirements.php

mail() configuration.
http://php.net/manual/en/mail.configuration.php

And according to this page http://php.net/manual/en/function.mail.php , your code does not have a 'message body' or content.

Author

Commented:
Dave Baldwin It works fine on Ubuntu 14.04 with postfix and php5
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
Dave Baldwin It works fine on Ubuntu 14.04 with postfix and php5
 You have already said that.  But you seem to be ignoring my comment that Postfix or Sendmail are NOT installed by default... but are Required by the PHP mail() function.  The Ubuntu and CentOS installations that I have did NOT have a SMTP server installed until I installed it.
dave gave the proper indications :
the mail php function relies on the system's sendmail command.

- this requires to be configured in php. check with phpinfo
- this requires the sendmail command to exist on the system. if postfix is installed, it does. be careful : you might be running in an fpm chrrot
- this requires the local MTA to be running and pickup to be configured properly. this should be the case with a postfix default install.

the php config can be checked with phpinfo and be enabling error output : the mail function will throw an error if it is unhappy.

the mail config can be tested by sending a mail from the command line using the mail command.
also try to tail /var/log/maillog or mail.log whichever exist

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial