php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21778 Mail Function causes apache to throw an error when sending mails with large att
Submitted: 2003-01-20 11:28 UTC Modified: 2003-02-13 19:57 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:3 of 4 (75.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: adrian at sourceconsulting dot co dot za Assigned:
Status: No Feedback Package: Mail related
PHP Version: 4.3.0 OS: win2k
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: adrian at sourceconsulting dot co dot za
New email:
PHP Version: OS:

 

 [2003-01-20 11:28 UTC] adrian at sourceconsulting dot co dot za
$attachment['file_name'] = "a.doc";
$attachment['mime_type'] = "application/msword";
$attachment['description'] = "Request for On-Site Support";
$attachment['encoded_string'] = CMS_file_get_contents("files/rfoss.b64",1); //returns the base64 encoded file as a string
	

$headers .= "From: ".$strFromName." <$strFrom>\r\n";
$headers .= "Reply-To:$strReplyTo <$strReplyTo>\r\n";
$headers .= "X-Priority: $intPriority\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= "\t boundary=\"SIMS------8f08ef19c30c5ab8bec2cd1a99c3578e\"\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n This is a MIME encoded message\r\n\r\n"; 
$headers .= "--SIMS------8f08ef19c30c5ab8bec2cd1a99c3578e\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
$headers .= base64_encode($strMessage)."\r\n\r\n\r\n\r\n";
$headers .= "--SIMS------8f08ef19c30c5ab8bec2cd1a99c3578e\r\n";
$headers .= "Content-Type: ".$attachment['mime_type']."; charset=iso-8859-1;\r\n";
$headers .= "\tname=".$attachment['file_name']."\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Description: ".$attachment['description']."\r\n\r\n";
$headers .= chunk_split($attachment['encoded_string']."\r\n\r\n";
$headers .= "--SIMS------8f08ef19c30c5ab8bec2cd1a99c3578e--\r\n";

$bSent  = mail($strTo, $strSubject,"", $headers);

The code shown works perfectly when sending small attachments.

If I try to send an attachment more than a few kbytes in size it causes apache to throw an error.

I have set php to use up to 20 mbytes of memory when executing a script in the hope that it was a buffer overflow but to no avail.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-03 13:51 UTC] pollita@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

Apart from providing the backtrace, you'll need to modify your script.

While versions of PHP prior to 4.3.0 allowed you to send mime encoded emails entirely inside the header, this was *NOT* correct behavior.  headers are only for headers, content belongs in the body.  Changes in 4.3.0 prevent data from being passed in this incorrect manner.

Granted it's exceedingly unlikely that this is causing apache to crash, but it's also exceedingly unlikely that the script you've shown will work on 4.3.0 at all, be the attachments large or small.  

Please ensure that you are:
(A) In fact using PHP 4.3.0 (Grabbing the latest stable snapshot from snaps.php.net would also be a good idea)
(B) Sending header data in the header parameter and sending content in the message patameter.

If, after trying the above, your application works fine, please return and update your bug status as appropriate.  If not, please provide a backtrace as described at top and also try to recreate the error from the command line (using the CLI version of PHP) to isolate if this error is apache related, or simply a mail() bug.
 [2003-02-13 19:57 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2008-11-24 07:39 UTC] anand_ayila at yahoo dot com
<?php
if($_POST['submit'])
{
		$fullname=$_POST['fullname'];
		$relatedname=$_POST['relatedname'];
		$gender=$_POST['gender'];
		$approxage=$_POST['approxage'];
		$missingdate=$_POST['day']."/".$_POST['month']."/".$_POST['year'];
		$missinglocation=$_POST['missinglocation'];
		$address=$_POST['address'];
		$phone=$_POST['phone'];
		$languages=$_POST['languages'];
		$height=$_POST['feet']."feet ".$_POST['inches']."inches";
		$hair=$_POST['hair'];
		$complexion=$_POST['complexion'];
		$mentalcondition=$_POST['mentalcondition'];
		$lastseen=$_POST['lastseen'];
		$to="swanand@pixelisolutions.com";
		$subject="Details of the Person";
		//format the message body
		//$message="This is the message body";
		
		$fileatt= $_FILES['image']['tmp_name'];
		$fileatt_type= $_FILES['image']['type'];
		$fileatt_name= $_FILES['image']['name'];
		if (is_uploaded_file($fileatt)) 
		{
			$file = fopen($fileatt,'rb');
			$data = fread($file,filesize($fileatt));
			fclose($file); 
			// Base64 encode the file data
			$data = chunk_split(base64_encode($data));
		}
		$semi_rand = md5(time());
		$mime_boundary = ==Multipart_Boundary_x{$semi_rand}x";
		$headers="From:";
		// Add the headers for a file attachment
		$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 
	if ($fileatt_name > "") 
	{
		$headers .= "Content-Type: {$fileatt_type};\n" .
		" name=\"{$fileatt_name}\"\n" .
		"Content-Transfer-Encoding: base64\n" .
		"Content-Disposition: attachment;\n" .
		" filename=\"{$fileatt_name}\"\n" .
		$data . "\n" .
		"--{$mime_boundary}\n";
	} 	
	$message .= "--$mime_boundary\n";
	$message .= "Content-Type: text/html; charset=UTF-8\n";
	$message .= "Content-Transfer-Encoding: 8bit\n\n";
	$message.="<html>\n<body>\n<table><tr><td>FULL NAME: $fullname </td></tr>";
	$message.="<tr><td>S/o W/o D/o:$relatednam</td></tr>";
	$message.="<tr><td>GENDER:$gende</td></tr>";
	$message.="<tr><td>APPROXAGE:  $approxage </td></tr>" ;
	$message.="<tr><td>MISSING DATE:  $missingdate </td></tr>" ;
	$message.="<tr><td>MISSING LOCATION:  $missinglocation</td></tr>" ;
	$message.="<tr><td>ADDRESS:  $address </td></tr>" ;
	$message.="<tr><td>PHONE:  $phone </td></tr>" ;
	$message.="<tr><td>LANGUAGES:  $languages </td></tr>" ;
	$message.="<tr><td>HEIGHT:  $height </td></tr>" ;
	$message.="<tr><td>HAIR:  $hair </td></tr>" ;
	$message.="<tr><td>COMPLEXION:  $complexion </td></tr>" ;
	$message.="<tr><td>MENTAL CONDITION:  $mentalcondition </td></tr>" ;
	$message.="<tr><td>LOCATION LAST SEEN: $lastseen </td></tr></table></body>\n</html>\n";
	$message .= "--$mime_boundary--\n\n";
		
	$message=wordwrap($message, 70);
	$ok = mail($to, $subject,$message,$headers);
	if ($ok) 
	{
		header("Location: http://www.webmaster.com/unknown/missingcomplaint.php");
	}
	else 
	{
		echo "<p>Mail could not be sent. Sorry!</p>";
	} 
}	

?>
Not able send the message which i have written in the php file.
but image is recieved to the mail without message body.
can any body help me out to solve this problem
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC