Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email won't attach

Status
Not open for further replies.

JCrou82

Programmer
Aug 23, 2002
265
US
I have a small app that uploads a file and then emails the uploaded file and other text box fields. My problem is that the file isn't being attached and the message text is being displayed twice in the email body. The image gets uploaded because I see it on the server.

Here is my emailing code:
Code:
	//*****Email Info
	$email_to = "email@domain.com";
	$email_from = "email@domain.com";	$email_subject = "Crystal Order ID: #" . $sOrderID;
	$email_message = "Customer Name: " . $custFName . " " . $custLName . "\n";	$email_message .= "Email Address: " . $custEmail . "\n";
	$email_message .= "Custom Text Line 1: " . $sCustText1 . " in " . $sTextFont1 . " Font Type\n";
	$email_message .= "Custom Text Line 2: " . $sCustText2 . " in " . $sTextFont2 . " Font Type\n"; 
	$email_message .= "Coupon Code: " . $sCouponCode . "\n";
	$email_message .= "Crystal Size: " . $sCrystalSize . "\n";
	$email_message .= "Crystal Selected: " . $sCrystalSKU . "\n";
	
	$email_message .= "\nPlease Send To:\n" . $custStreet . "\n" . $custCity . ", " . $custState . " " . $custZip . "\n";
	$email_message .= "\nIs this a residential address: " . $residential . "\n";
	$email_message .= "\n\nEnd Email\n";		
 
	//*****Email Construction
	$headers = "From: ".$email_from;
	$headers .= "\r\nBCC: other@domain.net\r\n";
	
	$semi_rand = md5(time()); 
	$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
	   
	$headers .= "\nMIME-Version: 1.0\n" . 
			"Content-Type: multipart/mixed;\n" . 
            " boundary=\"{$mime_boundary}\""; 

	$email_message .= "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type:text/plain; charset=\"iso-8859-1\"\n" . 
               "Content-Transfer-Encoding: 7bit\n\n" . 
	$email_message . "\n\n"; 

	//********************************************** First File ********************************************/
	$fileatt = "/directory/path/of/uploads/";                 
	$fileatt_type = "image/jpeg";
	$fileatt_name = $sFileUpload;
	
	$file = fopen($fileatt,'rb'); 
	$data = fread($file,filesize($fileatt)); 
	fclose($file); 
	
	$data = chunk_split(base64_encode($data)); 

	$email_message .= "--{$mime_boundary}\n" . 
                  "Content-Type: {$fileatt_type};\n" . 
                  " name=\"{$fileatt_name}\"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename=\"{$fileatt_name}\"\n" . 
                  "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                  "--{$mime_boundary}\n"; 
	unset($data);
	unset($file);
	unset($fileatt);
	unset($fileatt_type);
	unset($fileatt_name);

	$ok = @mail($email_to, $email_subject, $email_message, $headers);

I've tried using the directory path, I've tried with and without a trailing /. I've tried with the filename in the $fileatt variable and without it. I've tried using the http directory path and the path. None seem to attach the picture to be viewed my the email recipient. Also, I can't figure out why it sends the body of the message twice in the email.

Thanks in advance,
 
The problem with PHPMailer is, I don't have access to add files to the php.ini include_path. Isn't there just a missing line of code or something that will attach the picture. I mean maybe i'm going to the directory incorrectly?

Thanks guys
 
Here's the full email text that I receive:

MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_xf1a442a12c9539951fef43b54675603fx"

Customer Name: Javier Rivera
Email Address: taino202@aol.com
Custom Text Line 1: s in arial Font Type
Custom Text Line 2: in verdana Font Type
Coupon Code: ccmed
Crystal Size: 2
Crystal Selected: med2

Please Send To:
123 here
Nowhere, NY 10956

Is this a residential address: yes


End Email
This is a multi-part message in MIME format.

--==Multipart_Boundary_xf1a442a12c9539951fef43b54675603fx
Content-Type:text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Customer Name: Javier Rivera
Email Address: taino202@aol.com
Custom Text Line 1: s in arial Font Type
Custom Text Line 2: in verdana Font Type
Coupon Code: ccmed
Crystal Size: 2
Crystal Selected: med2

Please Send To:
123 here
Nowhere, NY 10956

Is this a residential address: yes


End Email


--==Multipart_Boundary_xf1a442a12c9539951fef43b54675603fx
Content-Type: image/jpeg;
name="1130757787.jpg"
Content-Transfer-Encoding: base64



--==Multipart_Boundary_xf1a442a12c9539951fef43b54675603fx
 
I must say that looks ok,
Do you use outlook express ? (or any email client really)
send your self an email (from oe) that does what you want it to.
When it arrives, open it up and click on file->properties and choose the details tab. You can then click on message source.
You will now be able to see the email headers. Thius window allows you to ctrl-c to copy to the clipboard
Check these against your code and also knock a small .php file out and use these lines as the input to the mail() function (if you see what I mean).
Post back, and in the mean time I'll have a look through your output
 
You can set paths for your script with

ini_set("include_path", "/my/path");



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top