Re: sending attachments via mail(), possible?

From: Date: Wed, 09 May 2001 19:17:35 +0000
Subject: Re: sending attachments via mail(), possible?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52163@lists.php.net to get a copy of this message
You have to open the file and encode it. Check out this: <html> <head> <title>FitnessQuest FTP user request form - results</title> </head> <body> <?php $date = exec("date"); $border="--==================_856811060==_"; /* Define the attachment and encode it base64 */ $filename="/var/www/sf/Ftp_User_Info.doc"; $fd = fopen($filename, "r"); $contents = fread($fd, filesize($filename)); $encoded=chunk_split(base64_encode($contents)); fclose($fd); /* Trim white spaces */ $request_by = trim($request_by); $email = trim($email); $company = trim($company); /* testing if form is filled out */ if (empty($email) ) { print "<h1>FAILED!</h1>"; print "<p>This form can't be sent! You did not fill the form out <b>completely!</b><br>The email address is missing!<br>"; print "<br><br>Please click the <b>back</b> button and fill in the email address<br>"; print "Thank you"; return; } if (empty($dr_ret) ) { print "<h1>FAILED!</h1>"; print "<p>This form can't be sent! You did not fill the form out <b>completely!</b><br>The system is not selected!<br>"; print "<br><br>Please click the <b>back</b> button and select a system (DR or Retail)<br>"; print "Thank you"; return; } #/* recipients */ $recipient = $email; #/* subject */ $subject = "FitnessQuest FTP account form"; #/* message */ $message .= "--$border\n"; $message .= "Content-Type: text/plain; charset=us-ascii\n\n"; $message .= "Attached is a FTP account access form. The form is in Microsoft Word 97 format, please fill it out completely\n"; $message .= "and email it back to ftp@fitnessquest.com. After a completed form has been recieved your FTP account will be\n"; $message .= "created. It will take approximately two working days to complete your FTP account. You will recieve an email with\n"; $message .= "username, password, and ftp server name. If you have questions, email ftp@fitnessquest.com or call your account\n"; $message .= "representative. Thank you\n\n"; $message .= "\n--$border\n"; $message .= "Content-Type: application/msword; name=\"Ftp\ User\ Info.doc\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment; filename=\"Ftp\ User\ Info.doc\"\n"; $message .= "\n"; $message .= "$encoded"; #$message .= "--$border\n"; /* Header infomation */ $headers .= "From: FTP Accounts <ftp@fitnessquest.com>\n"; $headers .= "X-Sender: <ftp@fitnessquest.com>\n"; $headers .= "Mime-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$border\"\n"; #/* and now mail it */ mail($recipient, $subject, $message, $headers); print "<h1>Notices Sent</h1>"; print "<h2><p>Emailed out!<br></h2>"; print "<p>Mail Sent to $recipient<p>"; /* Send notices to the distribution list */ /* Read Distribution list from text file */ $dlist = file("/var/www/sf/dlist"); $line = explode( ",", $dlist[0]); array_push ($line, $request_by); $dnumber = count($line); if ($dnumber == 0) { print "The list is empty<p>"; } for ($i=0; $i<$dnumber; $i++) { # print "$line[$i]<br>"; $line[$i] = trim($line[$i]); /* Clear Notices var */ unset ($not_mess); unset ($not_headers); unset ($not_sub); /* Notice Email Message */ $not_mess .= "--$border\n"; $not_mess .= "Content-Type: text/plain; charset=us-ascii\n\n"; $not_mess .= "An FTP access form was emailed to $email.\n"; $not_mess .= "Company name: $company\n"; $not_mess .= "$company will be a $dr_ret customer\n\n\n\n"; $not_mess .= "The request form was completed by $request_by on $date.\n\n"; # $not_mess .= "\n--$border\n"; /* Notice Subject */ $not_sub .= "FTP user setup notice"; /* Notice Headers */ $not_headers .= "From: FTP Accounts <ftp@fitnessquest.com>\n"; $not_headers .= "X-Sender: <ftp@fitnessquest.com>\n"; $not_headers .= "Mime-Version: 1.0\n"; $not_headers .= "Content-Type: multipart/mixed; boundary=\"$border\"\n"; /* Send Notice email to distribution list */ /* Diag testing */ # print "|$line[$i]|<br>"; # print "|$not_sub|<br>"; # print "|$not_mess|<br>"; # print "|$not_headers|<br><p>"; mail($line[$i], $not_sub, $not_mess, $not_headers); } ?> </body></html> ----- Original Message ----- From: "Christian Dechery" <christian@webstyle.com.br> To: <php-general@lists.php.net> Sent: Wednesday, May 09, 2001 3:10 PM Subject: [PHP] sending attachments via mail(), possible? > Is it possible to send attachments via mail() function? > > I tried it, and it didn't work out... the email I receive is all messed up, > and even the simple text part of it is screwed up. I now very little about > MIME, but I really need to send an attachment, any help? It's a text > attachment... > > This is the code I'm using: > > function send_email($body,$num_pedido,$filename) > { > define(NL,"\n"); > $boundary="test".chr(rand(65,91))."----".md5(uniqid(rand())); > $message="Segue em anexo dados referentes ao pedido $num_pedido.".NL.NL; > $message="Content-type: text/plain\nContent-transfer-encoding: > 7bit".NL.NL.$message; > $attach="Content-type: text/plain\nContent-transfer-encoding: > base64\nContent-disposition: attachment; filename=".$filename.NL.NL; > $attach.=base64_encode($body); > $attach.=NL; > $mail_body=$boundary.NL.$message.$boundary.NL.$attach.$boundary."-"; > $header="MIME-Version: 1.0\nContent-Type: > multipart/mixed;\n\tboundary=\"".$boundary."\"\nContent-Transfer-Encoding: > 7bit"; > // echo "<pre>$mail_body</pre>"; > mail("christian@webstyle.com.br","CDYOU Pedido: > ".$num_pedido,$mail_body,$header); > } > > the headers are sent perfectly... and if I echo the $mail_body (I think) > it's correct, but when I get the mail it's all screwed up... > > thanks... > _________________________________ > . Christian Dechery - CTO > .. WebDeveloper @ Webstyle! > .. http://www.webstyle.com.br > .. http://www.tanamesa.com.br > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#52163) next »