Send email Attachment


#1

I’m trying to send an email from a webpage that contains a file attachment (resume) loaded by visitor to the website.
I have tried to use formmail but it appears dreamhost doesn’t use or allow the attachment facility and suggest another route.
so… I’ve tried using a php script to send.
…and I have one that appears to work except the attachments appear all garbled.

I’m not sure if I have a problem with the script or it the issus is with mail server side??

The issue apears to be similar to this:
From another Forum


I encode an attachment using “$encoded_attach = chunk_split(base64_encode($contents));” on a new ISP and it emails a corrupted file?
Finally found the answer to my own question…

I needed to set the following variable before executing the encryption:

set_magic_quotes_runtime(0);

The file was corrupted on the new ISP since they have this set to 1 on their system and the old ISP had it at 0. This does not parse the encryped file with slashes for special characters.


I tried this but it isn’t working form me.
Here is my code for what it’s worth. Looking for directions.
OR BETTER ALTERNATIVE.


<?php $att1 = $_FILES['Att1']; $att_path1 = $_FILES['Att1']['tmp_name']; $att_name1 = $_FILES['Att1']['name']; $att_size1 = $_FILES['Att1']['size']; $att_type1 = $_FILES['Att1']['type']; #open, read then close the files $fp1 = fopen( $att_path1, "rb"); $file1 = fread( $fp1, $att_size1); fclose( $fp1 ); $first_name = $_POST['First_Name']; $last_name = $_POST['Last_Name']; $from_email = $_POST['Email']; $home_phone_area = $_POST['Home_Phone_Area']; $home_phone_number = $_POST['Home_Phone_Number']; $work_phone_area = $_POST['Work_Phone_Area']; $work_phone_number = $_POST['Work_Phone_Number']; $work_phone_extention = $_POST['Work_Phone_Extentionr']; $cell_phone_area = $_POST['Cell_Phone_Area']; $cell_phone_number = $_POST['Cell_Phone_Number']; $street = $_POST['Street']; $city = $_POST['City']; $provstate = $_POST['ProvState']; $postalcode = $_POST['Postal_Code']; $country = $_POST['Country']; $notes = $_POST['Notes']; $contact_me_byphone = $_POST['Contact_me_byPhone']; $contact_me_byemail = $_POST['Contact_me_byEmail']; #Email Subject $email_subject = $_POST['email_subject']; #create a boundary string $num = md5(time()); $str = "==Multipart_Boundary_x{$num}x"; #File 1 #encode the data for safe transit #and intersperse 76-character chunks with \n set_magic_quotes_runtime(0); $file1 = chunk_split(base64_encode($file1)); #recipient (to whom it may concern...) #sender (commentator) //$to .= "someone@mymail.com"; $to = $from_email . ", "; #define header $hdr = ''; $hdr .= "From:$from_email\r\n"; #cc: another recipient //$hdr .= "cc: someone@mymail.com\r\n"; #subject $subject = "". $email_subject . " From: " . $first_name . " " . $last_name; $hdr .= "MIME-Version: 1.0\r\n"; $hdr .= "Content-Type: multipart/mixed;"; $hdr .= "boundary=$num;\r\n"; #Set the outer boundary $hdr .= "--$num\r\n"; $hdr .= "Content-Type: text/plain\r\n"; $hdr .= "Content-Transfer-Encoding: 7bit\r\n\n"; #define message $msg = "On-Line Registration from Website...\n\n"; $msg .= "Name: " . $first_name . " " . $last_name . "\n\n"; $msg .= "Email: " . $from_email . "\n\n"; $msg .= "Home Phone: (" . $home_phone_area . ") " . $home_phone_number . "\n"; $msg .= "Work Phone: (" . $work_phone_area . ") " . $work_phone_number . " Ext: " . $work_phone_ext . "\n"; $msg .= "Cell Phone: (" . $cell_phone_area . ") " . $cell_phone_number . "\n\n"; $msg .= "Address: \n"; $msg .= " " . $street . "\n"; $msg .= " " . $city . " " . $provstate . " " . $postalcode . "\n"; $msg .= " " . $country . "\n\n"; $msg .= "Contact by Phone: " . $contact_me_byphone . "\n"; $msg .= "Contact by Email: " . $contact_me_byemail . "\n\n"; $msg .= "Notes: " . $notes . "\n\n"; $hdr .= "$msg\r\n"; $hdr .= "--$num\r\n"; #close the boundary #define the first non-text attachment $hdr .= "Content-Type: {$att_type1}; "; $hdr .= "name=\"{$att_name1}\"\r\n"; $hdr .= "Content-Transfer-Encoding: base64\r\n"; $hdr .= "Content-Disposition: attachment;\r\n\n"; $hdr .= "filename=\"{$att_name1}\"\r\n"; $hdr .= "$file1\r\n"; //$hdr .= "--$num\r\n"; #send the email now... $ok = mail( $to, $subject, $msg, $hdr); if($ok) { echo "

You will receive a copy of this email

"; echo "

Thank you.

"; } ?>

#2

Here is a similar script in Perl.

Your problem is you got the format of the message all wrong. Perhaps it would help if you changed the variable names to full words instead of abbreviations.

$headers should contain only he headers for the message itself.
$message should contain the different parts of the message.
Let’s add $part to represent a part.
Let’s add $part_headers and $part_body to represent the parts of a part.

For example.

[code]$part_headers = ‘Content-Type: text/plain\n’;
$part_body = ‘This is plain text.’;
$part = “$part_headers\n$part_body\n”;

$headers = “Content-Type: multipart/mixed; boundary=”$boundary"\n"’;
$message =
"–$bounday\n" .
$part .
"–$bounday\n" .
$part .
"–$bounday\n" .
$part .
// final boundary delimiter ends with hyphens
"–$bounday–\n";
[/code]If you bother to write your output to disk or to screen, you’d see you got stuff in the wrong place, and that you have the final boundary commented out. I haven’t actually tested your code, but what I’ve pointed out are the obvious mistakes.

:cool: Perl / MySQL / HTML+CSS


#3

Thanks… for the reply.
I’m just a beginnner with this and took what was supposed to be a working model.
Trying to figure out syntax and such at this time.

If you follow this link, you’ll see the same stuff.


#4

http://forums.devshed.com/archive/t-192423


#5

Ok, I’ve played clean up … still doesn’t appear to help me see the attachment.

<?php # Set the File Attributes $att1 = $_FILES['User_File']; $att_path1 = $_FILES['User_File']['tmp_name']; $att_name1 = $_FILES['User_File']['name']; $att_size1 = $_FILES['User_File']['size']; $att_type1 = $_FILES['User_File']['type']; # Open, read then close the files $fp1 = fopen( $att_path1, "rb"); $file1 = fread( $fp1, $att_size1); fclose( $fp1 ); # Get the Field Names from the Form $first_name = $_POST['First_Name']; $last_name = $_POST['Last_Name']; $from_email = $_POST['Email']; $home_phone_area = $_POST['Home_Phone_Area']; $home_phone_number = $_POST['Home_Phone_Number']; $work_phone_area = $_POST['Work_Phone_Area']; $work_phone_number = $_POST['Work_Phone_Number']; $work_phone_extention = $_POST['Work_Phone_Extentionr']; $cell_phone_area = $_POST['Cell_Phone_Area']; $cell_phone_number = $_POST['Cell_Phone_Number']; $street = $_POST['Street']; $city = $_POST['City']; $provstate = $_POST['ProvState']; $postalcode = $_POST['Postal_Code']; $country = $_POST['Country']; $notes = $_POST['Notes']; $contact_me_byphone = $_POST['Contact_me_byPhone']; $contact_me_byemail = $_POST['Contact_me_byEmail']; $email_subject = $_POST['email_subject']; #create a boundary string $num = md5(time()); $str = "==Multipart_Boundary_x{$num}x"; #encode the data for safe transit #and intersperse 76-character chunks with \n set_magic_quotes_runtime(0); $file1 = chunk_split(base64_encode($file1)); # Set up Message $to = $from_email . ", "; //$to .= "someone@mymail.com"; $subject = "". $email_subject . " From: " . $first_name . " " . $last_name; # Define Message # Define Email Message Header $msg1_header = "Content-Type: text/plain\n"; $msg1_header .= "Content-Transfer-Encoding: 8bit\r\n"; # Define Email Message Text $msg1_text = "On-Line Registration from Website...\n\n"; $msg1_text .= "Name: " . $first_name . " " . $last_name . "\n\n"; $msg1_text .= "Email: " . $from_email . "\n\n"; $msg1_text .= "Home Phone: (" . $home_phone_area . ") " . $home_phone_number . "\n"; $msg1_text .= "Work Phone: (" . $work_phone_area . ") " . $work_phone_number . " Ext: " . $work_phone_ext . "\n"; $msg1_text .= "Cell Phone: (" . $cell_phone_area . ") " . $cell_phone_number . "\n\n"; $msg1_text .= "Address: \n"; $msg1_text .= " " . $street . "\n"; $msg1_text .= " " . $city . " " . $provstate . " " . $postalcode . "\n"; $msg1_text .= " " . $country . "\n\n"; $msg1_text .= "Contact by Phone: " . $contact_me_byphone . "\n"; $msg1_text .= "Contact by Email: " . $contact_me_byemail . "\n\n"; $msg1_text .= "Notes: " . $notes . "\n\n"; $message1 = "$msg1_text"; # Define the first attachment $attachment_hdr .= "Content-Type: {$att_type1}; "; $attachment_hdr .= "name=\"{$att_name1}\"\r\n"; $attachment_hdr .= "Content-Transfer-Encoding: base64\r\n"; $attachment_hdr .= "Content-Disposition: attachment;\r\n\n"; $attachment_file .= "filename=\"{$att_name1}\"\r\n"; $attachment_file .= "$file1\r\n"; $attachment = "$attachment_hdr\n$attachment_file\n"; # Define the Email Structure # Define Email Header $header = "From: $from_email\r\n"; //$header .= "cc: someone@mymail.com\r\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed;"; $header .= "boundary=$num;\r\n"; $header .= "--$num\r\n"; $header .= "$msg1_header"; # Define Email Body $body = $message1 . "--$num\r\n" . $attachment . "--$num--\r\n"; #send the email now... $ok = mail( $to, $subject, $body, $header); if($ok) { echo "

You will receive a copy of this email

"; echo "

Thank you.

"; } ?>

#6

You probably should do a little debug.

Change $file1 to “THIS IS NOT A FILE”

Set $ok to true, instead of calling mail()

Add an echo:

echo “

HEADERS\n$header\nBODY\n$body

And you’ll be able to see where you’re output has gone wrong.

Compare your output to that of my perl script:
http://atropos.openvein.org/web/dreamhost/php/example.txt

You still have output in the message headers instead of the message body.
The file attachment part is improperly formatted.

:cool: Perl / MySQL / HTML CSS


#7

I’ve got lots of info on mail format (including MIME multipart formats) in my site:

http://mailformat.dan.info/

– Dan


#8

Thanks guys
Tried to clean up the code I inherited.
Looking at the debugging and trying a few more things…Thanks Dan for the email syntax stuff … much appreciated.

atopos7, What output stuff are you referring to specifically that is showing in the message header? I’ll clean that up.

… still not working for me… think my issue may be with the encoding decoding base64 (or 7 vs 8 bit) not sure.

I’m seeing the attachment as a msword icon or a pdf icon or a jpg icon if I switch files. But the contents of each is all garbled.

my output
You will receive a copy of this email
Thank you.
HEADERS
From: xxx@mymail.com
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary=daf99398a8e801e2da47c084fae4816c;
–daf99398a8e801e2da47c084fae4816c
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

BODY
On-Line Registration from Website…

Name: adsfa adsfasdf

Email: asdfasdf@hismail.com

Home Phone: ()
Work Phone: () Ext:
Cell Phone: ()

Address:

Contact by Phone:
Contact by Email:

Notes:

–daf99398a8e801e2da47c084fae4816c
Content-Type: application/msword; name="testresume.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

filename="testresume.doc"
VEhJUyBJUyBOT1QgQSBGSUxF

–daf99398a8e801e2da47c084fae4816c–

**** Note: The line under the “filename=testresume.doc” is the debug text — Changed $file1 to "THIS IS NOT A FILE"
So. I’m thinking it’s not decoding or has encoded too many times or something


#9

Again, you need to compare your output to mine.

Here is your message headers:HEADERS From: xxx@mymail.com MIME-Version: 1.0 Content-Type: multipart/mixed;boundary=daf99398a8e801e2da47c084fae4816c; --daf99398a8e801e2da47c084fae4816c Content-Type: text/plain Content-Transfer-Encoding: 7bitThe problem here is you have part of the message body in the message headers.

Here is a section from the message body:[code]–daf99398a8e801e2da47c084fae4816c
Content-Type: application/msword; name="testresume.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

filename="testresume.doc"
VEhJUyBJUyBOT1QgQSBGSUxF[/code]Proper format looks like this though.

[code]–8Dx19XpKG3W8xtfRX2LWeW3U
Content-Type: image/jpeg; name="2612492.jpg"
Content-Disposition: attachment; filename=2612492.jpg
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAgEASABIAAD/7RG6UGhvdG9zaG9wIDMuMAA4QklNA+kKUHJpbnQgSW5mbwAA[/code] :cool: Perl / MySQL / HTML+CSS


#10

Ok, I’ve added the
"Content-Type: text/plain
Content-Transfer-Encoding: 7bit"
to be included in the body… but that doesn’t appear to be the problem.
Regardless of where the message header (Body part header the "plain text stuff) gets placed… I’m still not seeing the contents of my file… all garbled. This is the problem… if syntax is the issue then i’d by that… but.

You will receive a copy of this email
Thank you.
HEADERS
From: xxx@mymail.com
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary=4f2beb627972822578f7c2a5574a1cb2;
–4f2beb627972822578f7c2a5574a1cb2

BODY
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On-Line Registration from Website…

Name: lastname firstname

Email: xxx@mymail.com

Home Phone: ()
Work Phone: () Ext:
Cell Phone: ()

Address:

Contact by Phone:
Contact by Email:

Notes:

–4f2beb627972822578f7c2a5574a1cb2
Content-Type: application/msword; name="testresume.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

filename="testresume.doc"
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAIQAAAAAAAAAA
EAAAIwAAAAEAAAD+////AAAAACAAAAD/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


#11

You’ve still get the output wrong, mostly because you have not read the specifications at all apparently. You’ve got a lot of reading to do. Here is what dtobias says on http://mailformat.dan.info/headers/intro.html

And to understand where you went wrong with the message headers, read:

http://mailformat.dan.info/headers/mime.html

:cool: Perl / MySQL / HTML+CSS


#12

Why not just use MIME::Tools


#13

I really appreciate your assistance and I maybe struggling with “The Basic Syntax” =… But I thought I had it.

I’m getting an email (I expect) - with what appears to be appropriate headers, with the appropriate body message I expect.

What I’m having problems with is the Attachment.
I played around last night and …I can get a plain text attachment but not a msword or pdf. Something to do with the encode and decode base 64 stuff. - is causing the garbled messages. Now if you says that is a result of my syntax errors with formatting headers etc. then I guess I’ll have to get some more education.

FYI, the mime link appears to be broken.

(Geeze… I was looking for a simple function, which someone else had provide a ready made solution)

This is my latest Header / Body stuff - should match with yours.
HEADERS
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=9df1d07f5b6a71d28b5ec7f3c3787563;

BODY
–9df1d07f5b6a71d28b5ec7f3c3787563
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On-Line Registration from Website…

Name: xxxxxxxxxxx
Email: xxxxxxxxxxxxx

Home Phone: ()
Work Phone: () Ext:
Cell Phone: ()

Address:
Street:
City: Prov/State: Postal Code:
Country:

Contact by Phone:
Contact by Email:

Notes:

–9df1d07f5b6a71d28b5ec7f3c3787563
Content-Type: text/plain;
Content-Transfer-Encoding: base64
name="testresume.txt"
This is a test of a text file.
–9df1d07f5b6a71d28b5ec7f3c3787563–

FYI. My msword attachment (Part) looks like this…

–d551ad9e8703320fe28075d618f84bd7
Content-Type: application/msword;
Content-Transfer-Encoding: base64
name="testresume.doc"
ÐÏࡱá>þÿ !#þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿì¥Á% ð¿bjbj%ç%ç .GGÿÿÿÿÿÿl¬¬¬¬¬¬¬ÀÚÚÚÚæÀC¶þþþþþþþþÂÄÄÄÄÄÄ$ù Nè¬þþþþþ謬þþýþ¬þ¬þÂþ¤¬¬ÂþòÀ™’‰ÊÑÅÀÚ
ÂÂ0CÂggÂÀÀ¬¬¬¬ÙTest Resume - Word Doc
ýþ,1h°Ð/ °à=!°"°# $ %°°Ä°ÄÄ
i<@ñÿ<NormalOJQJ_HaJmH sH tH


#14

Well now your script it is not putting the base64 encoding of the file in the message at all.

You still have the parts of the message improperly formatted. It’s not freakin’ hard. It goes like
this

–BOUNDARY
HEADER: VALUE
HEADER: VALUE

BODY LINE
BODY LINE

Now you’ve got it like
–BOUNDARY
HEADER: VALUE
HEADER: VAL
UE
BODY LINE
BODY LINE

Which is no good.

:cool: Perl / MySQL / HTML+CSS


#15

OK, I obviously can’t see the forest through the trees…

I’ve included my latest php script.
Can you point out the specific lines/issues you see that are in error (I’ll “get it” once I see what I’m doing wrong)

My code…
(note I still have some commented lines in that I was playing around with)

<?php //$str = 'This is an encoded string'; // echo base64_encode($str); //$str2 = base64_encode($str); // echo base64_decode($str2); //$str3 = base64_decode($str2); // echo $str3; # Set the File Attributes $att1 = $_FILES['User_File']; $att_path1 = $_FILES['User_File']['tmp_name']; $att_name1 = $_FILES['User_File']['name']; $att_size1 = $_FILES['User_File']['size']; $att_type1 = $_FILES['User_File']['type']; # Open, read then close the files $fp1 = fopen( $att_path1, "rb"); $filecontents = fread( $fp1, $att_size1); fclose( $fp1 ); #encode the data for safe transit #and intersperse 76-character chunks with \n set_magic_quotes_runtime(0); $filecontents = chunk_split(base64_encode($filecontents)); //$filecontents = base64_decode($filecontents); # Get the Field Names from the Form $first_name = $_POST['First_Name']; $last_name = $_POST['Last_Name']; $from_email = $_POST['Email']; $home_phone_area = $_POST['Home_Phone_Area']; $home_phone_number = $_POST['Home_Phone_Number']; $work_phone_area = $_POST['Work_Phone_Area']; $work_phone_number = $_POST['Work_Phone_Number']; $work_phone_extention = $_POST['Work_Phone_Extentionr']; $cell_phone_area = $_POST['Cell_Phone_Area']; $cell_phone_number = $_POST['Cell_Phone_Number']; $street = $_POST['Street']; $city = $_POST['City']; $provstate = $_POST['ProvState']; $postalcode = $_POST['Postal_Code']; $country = $_POST['Country']; $notes = $_POST['Notes']; $contact_me_byphone = $_POST['Contact_me_byPhone']; $contact_me_byemail = $_POST['Contact_me_byEmail']; $email_subject = $_POST['email_subject']; #create a boundary string $num = md5(time()); $str = "==Multipart_Boundary_x{$num}x"; # Set up Message $to = $from_email . ", "; //$to .= "someone@mymail.com"; $subject = "". $email_subject . " From: " . $first_name . " " . $last_name; # Define Message $message = "Content-Type: text/plain\n"; $message .= "Content-Transfer-Encoding: 7bit\r\n"; $message .= "On-Line Registration from Website...\n\n"; $message .= "Name: " . $first_name . " " . $last_name . "\n"; $message .= "Email: " . $from_email . "\n\n"; $message .= "Home Phone: (" . $home_phone_area . ") " . $home_phone_number . "\n"; $message .= "Work Phone: (" . $work_phone_area . ") " . $work_phone_number . " Ext: " . $work_phone_ext . "\n"; $message .= "Cell Phone: (" . $cell_phone_area . ") " . $cell_phone_number . "\n\n"; $message .= "Address: \n"; $message .= "Street: " . $street . "\n"; $message .= "City: " . $city . " Prov/State: " . $provstate . " Postal Code: " . $postalcode . "\n"; $message .= "Country: " . $country . "\n\n"; $message .= "Contact by Phone: " . $contact_me_byphone . "\n"; $message .= "Contact by Email: " . $contact_me_byemail . "\n\n"; $message .= "Notes: " . $notes . "\n\n"; # Define the first attachment $attachment = "Content-Type: {$att_type1}; "; $attachment .= "name=\"{$att_name1}\"\r\n"; $attachment .= "Content-Transfer-Encoding: base64\r\n"; $attachment .= "Content-Disposition: attachment;\r\n"; $attachment .= "filename=\"{$att_name1}\"\r\n"; //$attachment .= "$filecontents2\r\n"; $attachment .= "$filecontents\r\n"; # Define the Email Structure # Define Email Header $header = "From: $from_email\r\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed;"; $header .= "boundary=$num;\r\n\n"; # Define Email Body $body = "--$num\r\n" . $message . "--$num\r\n\n" . $attachment . "--$num--\r\n"; #send the email now... $ok = true; $ok = mail( $to, $subject, $body, $header); if($ok) { echo "

You will receive a copy of this email

"; echo "

Thank you.

"; echo "
HEADERS\n$header\nBODY\n$body\n
"; } ?>

#16

Just use this function instead.

[code]function mime_part($boundary, $body, $type, $charset, $disposition, $filename, $encoding) {
/*
This function returns a string value representing a MIME part.
These arguments are optional: $charset, $filename, and $encoding.
$encoding should be set if $body is not a multipart entity.
*/

$part = “–$boundary\n”;

if (isset($charset)) {
$part .= “Content-Type: $type; charset=”$charset"";
}
else {
$part .= “Content-Type: $type”;
}

if (isset($filename)) {
$part .= “;\n name=”$filename"\n";
$part .= “Content-Disposition: $disposition;\n filename=”$filename"\n";
}
else {
$part .= “\n”;
$part .= “Content-Disposition: $disposition\n”;
}

if (isset($encoding)) {
$part .= “Content-Transfer-Encoding: $encoding\n”;
}

$part .= “\n$body\n”;

return $part;
}

// Example use of function.

$body =
“This is a multi-part message in MIME format.\n” .
mime_part($boundary, $message_text, ‘text/plain’, ‘us-ascii’, ‘inline’, NULL, ‘8bit’) .
mime_part($boundary, $file_base64, ‘image/gif’, NULL, ‘attachment’, ‘something.gif’, ‘bas64’) .
"–$boundary–\n";[/code]
:cool: Perl / MySQL / HTML CSS


#17

Thanks, my app is working.
Appreciate the patience.

Issue resolved.