Weird problem with PHP mail() under Linux.

Posted by Vilx- on Stack Overflow See other posts from Stack Overflow or by Vilx-
Published on 2009-02-18T20:15:12Z Indexed on 2010/05/27 0:21 UTC
Read the original article Hit count: 250

Filed under:
|
|

This is the case when it "works on my machine". Except that my machine is Windows, and the target is some sort of Linux.

The idea is that the mail() function puts a newline between the MIME-Version and Content-Type headers, thus breaking the whole thing. Here's the code, simpliefied as much as possible:

<?php
		$HTMLPart = chunk_split(base64_encode('<html><body style="color: red">Test.</body></html>'));
		$PlaintextPart = chunk_split(base64_encode('>>> TEST <<<'));

$Headers     =<<<AKAM
From: "My Test" <[email protected]>
Reply-To: [email protected]
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="9-1410065408-1410065408=:27514"
AKAM;

$Body        =<<<AKAM
This is a multi-part message in MIME format.

--9-1410065408-1410065408=:27514
Content-Type: text/plain; charset="windows-1252"
Content-Transfer-Encoding: base64

$PlaintextPart
--9-1410065408-1410065408=:27514
Content-Type: text/html; charset="windows-1252"
Content-Transfer-Encoding: base64

$HTMLPart
--9-1410065408-1410065408=:27514--
AKAM;
	echo 'Try 3: ';
	echo mail('[email protected]', 'Testmail', $Body, $Headers) ? 'WIN' : 'FAIL';
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mail