Jump to content


This topic is now archived and is closed to further replies.


Any expert comment on BIG Problrm

Recommended Posts

ok anyhow i managed to send attachemnet with mail using php, but problem is that , while opening in rediffmail,yahoomail,my attachement is displayed in below format, though i attached a excle file & i tried on notepad file also.

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

Content-Type: application/x-msdownload;
Content-Disposition: attachment;
Content-Transfer-Encoding: base64


infact it should have displayed in file attachement(as regular attacement) that can be downloaded form mail like a seprate file.
with this attachement i can't downlaod file.what wrong with my coding: below is code:-

PHP :code:
//require_once "Mail.php";
#--------From Html form
$to      = $_POST['to'];

$from    = $_POST['from'];

$subject = $_POST['subject'];

$message = $_POST['message'];

// Obtain file upload vars

$fileatt      = $_FILES['fileatt']['tmp_name'];

$fileatt_type = $_FILES['fileatt']['type'];

$fileatt_name = $_FILES['fileatt']['name'];

#$headers = "From: $from";
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => false,
    'username' => $username,
    'password' => $password));

if (is_uploaded_file($fileatt)) {

  // Read the file to be attached ('rb' = read binary)

  $file = fopen($fileatt,'rb');

  $data = fread($file,filesize($fileatt));


  // Generate a boundary string

  $semi_rand = md5(time());

  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

  // Add the headers for a file attachment

  $headers .= "\nMIME-Version: 1.0\n" .

              "Content-Type: multipart/mixed;\n" .

              " boundary=\"{$mime_boundary}\"";

  // Add a multipart boundary above the plain message

  $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" .

            $message . "\n\n";

  // Base64 encode the file data

  $data = chunk_split(base64_encode($data));

  // Add file attachment to the message

  $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" .


#$from = "sunil <sunil.phogat@sugaldamani.com>";
#$to = "sunil <afsa23@rediffmail.com>";
#$subject = "Hi!";
#$body = "Hi,\n\nHow are you?";

$host = "smtp.registeredsite.com";
$username = "sunil.phogat@registeredsite.com";
$password = "****";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => false,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $message);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");

Share this post

Link to post
Share on other sites
Take a look at PHPmailer at http://phpmailer.sourceforge.net/

This class makes sending attachments very easy.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.