Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 08:53 AM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default word file corrupted after mail

when mail word file it is sent successfuly but when downloaded then it is corrupted. I don't know where is the mistake in the code. Plse check the code:-

email code is as follows
----------------
<?
function send_mail($myname, $myemail, $contactemail, $subject, $message, $attachtype, $type, $topic) {

$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

//Finding whether the attachment type is Abstract or Paper
if ($type=="A")
  $stype="Abstract";
elseif ($type=="P")
   $stype="Paper";

//Checking the topic
switch ($topic)
{
case 1:
        $stopic="Optoelectronics(including IR & PV)";
        break;
case 2:
      $stopic="VLSI & ULSI Technologies";
       break;
case 3:
      $stopic="Modelling and Simulation";
      break;
case 4:
      $stopic="Nano-Technology";
      break;
case 5:
      $stopic="High Frequency Devices";
      break;
case 6:
      $stopic="Growth & Characterization";
      break;
case 7:
      $stopic="Sensors & MEMS";
      break;
case 8:
      $stopic="Organic Semiconductors";
      break;
case 9:
      $stopic="Emerging Technoogies";
      break;
}

//Adding the Name and the Email of the Sender in the email Message
$message = "Name:- " . $myname . "\n" . "Email:- " . $myemail . "\n" . "Attachment Type & Version:- " . $attachtype . "\n". "Type:- ". $stype . "\n". "Topic:- " . $stopic . "\n\n" . $message ;

//Giving a unique subject to all the mails.
$today = date("F j, Y, g:i:s a") ;
$subject = $subject ." :- " . $today;

$headers = "From: secretary@iwpsd.net";


if (is_uploaded_file($fileatt)) {

  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);


  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";


  $headers .= "\nMIME-Version: 1.0\r\n" .
              "Content-Type: multipart/mixed;\r\n" .
             // "Content-Type: application/msword \n" .
              " boundary=\"{$mime_boundary}\"";

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


  $data = chunk_split(base64_encode($data)); //
    // $data =convert_uuencode($some_string);
//$data = chunk_split($data);



  $message .= "--{$mime_boundary}\r\n" .
              "Content-Type: {$fileatt_type};\r\n" .
              " name=\"{$fileatt_name}\"\r\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\r\n\n" .
              $data . "\r\n\n" .
              "--{$mime_boundary}--\r\n";
}

$message = StripSlashes($message);



return(mail($contactemail, $subject, $message, $headers));

}// End of the function send-mail

$sendername=$_POST['txtname'];
$senderemail=$_POST['txtemail'];
$sendersubject=$_POST['txtsubject'];
$sendermessage=$_POST['txtmessage'];
$senderattachtype=$_POST['txtatttype'];
$sendertype=$_POST['rdtype']; // Radio Button Showing Abstract or Paper
$sendertopic=$_POST['ddltopic'];
$sendercontactemail="papersubmission.iwpsd@gmail.c om";

if (send_mail($sendername, $senderemail, $sendercontactemail, $sendersubject, $sendermessage,$senderattachtype,$sendertype,$send ertopic)) {
  print "SENT!";
} else {
  print "FAILED!";
}

?>
----------------
 
Old March 27th, 2005, 09:47 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I had a similar problem once, it turned out there was a single space inserted at the beginning of a file. To troubleshoot your problem I suggest using the technique that I did then, open the non-corrupted file in Wordpad or Notepad, and do the same with the corrupted file. Compare the two side-by-side and see what the difference is.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
Corrupted mdb file edcaru Access 4 April 19th, 2012 10:38 AM
"Pushing" from Access to Word via Mail Merge Loralee BOOK: Access 2003 VBA Programmer's Reference 2 March 8th, 2006 10:20 PM
Mail Merge with MS Word bezaman Classic ASP Basics 1 October 6th, 2005 04:13 PM
Send Mail from Word with formatted Body saimen Excel VBA 1 February 10th, 2005 07:53 AM
Wrap Up feature (like Word Mail Merge) jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 28th, 2004 03:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.