[BlueOnyx:17676] Re: phpmailer problem php 5.5

Michael Stauber mstauber at blueonyx.it
Sun May 24 13:08:45 -05 2015


Hi Wisja,

> After the update/installation some of my users started complaining that their 
> mailscripts stopt working.
>
> We have had that kind of problems in the past with older php scripts and in 
> those cases adding the -f emailadress to sendmail in php.ini would solve it.
> The error seen in de errorlog is: Malformed header from script, followed by the 
> path to the websites script.
> It seems that the -f switch is no longer working with the sendmail directive in 
> php.ini

There are a lot of ways how mail can be sent from PHP scripts. The
mail() function is just one of them and it usually works pretty well.

However: For security reasons and to make it easier to detect PHP
scripts that are used for sending SPAM we handle things a bit different
on BlueOnyx:

The php.ini has this in it:

auto_prepend_file = /usr/sausalito/configs/php/set_php_headers.php
sendmail_path = /usr/sausalito/sbin/phpsendmail

So emails are not passed directly to Sendmail, but take a small round about.

First of all the "auto_prepend_file" is pre-pended to all PHP scripts
and sets some environment variables that help us to identify the
location of the script and who owns it.

If scripts then send emails, those emails don't get passed directly to
Sendmail. Instead they are passed to the Perl-script
/usr/sausalito/sbin/phpsendmail, which reads the environment variables
of the script in question and logs the mail activity from this script to
/var/log/maillog:

# Log the activity into /var/log/maillog with all the info we have gathered:
system("/usr/bin/logger -p mail.info sendmail-wrapper-php:
site=$HTTP_HOST, client=$REMOTE_ADDR, script=$PWD$SCRIPT_NAME, uid=$UID,
user=$OWNER");

Lastly this Perl script passes the email to Sendmail to actually send it:

# Actually send the email by passing it to Sendmail:
system("/usr/sbin/sendmail -t -i $*");

The $* at the end makes sure that a sender that was set via -f is
appended as well as the actual message to be sent. So you would need to
actually set the -f in the script in question. NOT in the php.ini.

Or: If you cannot do that for whatever reasons, then enable suPHP and
set a "Web Owner" for the virtual site. Emails will then be sent as the
user who owns the Vsite.

FWIW: The easiest way to send email from PHP is this:

mail("$recipient", "$subject", $body, "From:" . $sender);

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list