I recently upgraded PHP to version 5 and just realized my script for sending mail has ceased working.
This script has worked great for years with little modification (oasted below).
I was working on a new script that used this function and upon testing, realized I never got an email. Then I started investigating further and realized I hadn't gotten any email since right before the php upgrade. Probably not a coincidence.
I don't get any errors either, just no mail ever comes.
Since I didn't use the mail() function and instead directly utilized the sendmail program, I thought I would avoid php.ini issues....but perhaps I thought wrong.
Do any of you guys know what may have gone wrong? Is there something in my code that doesn't work in php5 bu also doesn't throw an error?
<?php
function mailMessage($emailRecipient, $emailSender, $emailName, $emailSubject, $emailText, $mailer)
{
$message = '
<style>
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
background-image: url(/images/bg_fill_bottom.png);
}
.message {
padding:5px;
border-style:solid;
border-width:thin;
border-color:#999999;
}
.browserInfo {
padding:5px;
background-color:#EEEEEE;
border-style:solid;
border-width:thin;
border-color:#999999;
color: #666666;
font-size:10px;
}
</style>
';
$message .= '<span style="color=#3A4861; font-size:14px; font-weight:bold;">'.$emailSubject."</span><br/>\n";
$message .= "The following message was received from ".((strlen($mailer))?$mailer:"your website email form").":<br />\n";
$message .= "<br />\n".'<div class="message">';
$message .= "Name: $emailName<br />\nEmail Address: $emailSender<br />\n";
$message .= "<br />\n".nl2br($emailText);
$message .= '</div>';
$message .= "<br /><br />\n\n".'<div class="browserInfo">';
$message .= "Additional Information for $emailName:<br />\n" .
"IP Address: " . getUserIP() . "<br />\n" .
"Browser: " . getenv("HTTP_USER_AGENT");
$message .= '</div>';
//$emailHeaders = "MIME-Version: 1.0\n";
$emailHeaders = "From: $emailName <$emailSender>\n";
$emailHeaders .= "Return-Path: <$emailSender>\n";
$emailHeaders .= "X-Sender: <$emailSender>\n";
$emailHeaders .= "X-Mailer: PHP\n";
$emailHeaders .= "MIME-Version: 1.0\n";
$emailHeaders .= "Content-Type: text/html; charset=iso-8859-1\n";
$mail = popen("/var/qmail/bin/sendmail -f $emailSender $emailRecipient", "w");
if (strlen(getenv("HTTP_USER_AGENT")))
{
if ($mail)
{
fputs($mail, "To: $emailRecipient\n");
fputs($mail, "Subject: $emailSubject\n");
fputs($mail, $emailHeaders . "\n");
fputs($mail, $message);
fputs($mail, "\n");
pclose($mail);
} else {
$GLOBALS['___m'] = "There was an error processing the request. We're sorry for the inconvenience.";
break;
}
} else {
$GLOBALS['___m'] = "The form cannot be processed using your current browser. We're sorry for the inconvenience.";
break;
}
}
?>