php.net |  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: -
Votes:3
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ikonta at yandex dot ru
New email:
PHP Version: OS:

 

 [2015-07-15 11:56 UTC] ikonta at yandex dot ru
Description:
------------
---
From manual page: http://www.php.net/function.mail
---
Fix of https://bugs.php.net/bug.php?id=68776 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:
---------------
<?php
…
// 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 http://php.net/manual/en/function.mail.php

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/mail.inc on line 47

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

Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC