Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

php mail() issues?

See attached.

This function has been used since Dec. 31, 2014 (date last changed) until last Friday. It has been executed hundreds of times successfully.

Starting then, it produces the error message "mail send ... ERROR!"

In the attached version, I added the php error reporting at the top,

It now shows:

Warning: mail(): Multiple or malformed newlines found in additional_header in /home/fwsprinkler/public_html/fwsprinklercdb.info/mail_attachment.php on line 28
kk =
mail send ... ERROR!

Is it possible that the host upgraded the version of php & the newer version has some issue with this?

<?php
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
    $file = $path.$filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
	$kk = mail($mailto, $subject, "", $header);
	echo "kk = " . $kk . "<br>";
    if ($kk) {
        echo "mail send ... OK"; // or use booleans here
    } else {
        echo "mail send ... ERROR!";
    }
}
?>

Open in new window

mail-attachment.php
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Korts

ASKER

Ray,

This is at GoDaddy, your favorite.

The current version is 5.4. I don't know if I can find out what it was last Friday.

I didn't see what version was being addressed in https://bugs.php.net/bug.php?id=68776
I think I will try the fix suggested at the other link. Seems odd, but if it works............

Thanks
Yeah, it's easy to test their suggestion!