|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70082 mail() function description should provide right example of multi-part mail
Submitted: 2015-07-15 11:56 UTC Modified: -
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: ikonta at yandex dot ru Assigned:
Status: Open Package: Mail related
PHP Version: Irrelevant OS: GNU/Linux 3.x kernel
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ikonta at yandex dot ru
New email:
PHP Version: OS:


 [2015-07-15 11:56 UTC] ikonta at yandex dot ru
From manual page:
Fix of in php-5.6.10 pointed rather important miss:
Internet provides many _incorrect_ (!) examples of a widely spread task sending of multi-part emails (usually — attached files), but official documentation doesn't provide the correct solution.

Providing slightly modified verified example from Internet, which correctly sends mails with attached files with php-5.6.11.

Test script:
// Common header:
$mail_header = "From: ".$from_name." <".$from_mail.">\r\n";
$mail_header .= "Reply-To: ".$replyto."\r\n";
$mail_header .= "MIME-Version: 1.0\r\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
// Multi-part body:
$mail_body = "--".$uid."\r\n";
$mail_body .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$mail_body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$mail_body .= $message."\r\n\r\n";
$mail_body .= "--".$uid."\r\n";
$mail_body .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$mail_body .= "Content-Transfer-Encoding: base64\r\n";
$mail_body .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$mail_body .= $content."\r\n\r\n";
$mail_body .= "--".$uid."--";
// Really necessary parametr:
$envelope = "-f" . $from_mail;
//And sending message itself:
mail($mailto, $subject, $mail_body, $mail_header, $envelope);


Expected result:
I expect to see the quoted script (or some similiar) in list of examples in

Actual result:
But now I had to search web following error string:

Jul 15 13:20:13 web httpd: PHP Warning:  mail(): Multiple or malformed newlines found in additional_header in /var/www/project/inc/ on line 47

Finding mostly old, unsupported, incorrect and incompatible with php-5.6.10+ examples.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 01:01:29 2024 UTC