sun14php Posted July 12, 2006 Share Posted July 12, 2006 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.--==Multipart_Boundary_xa7bb2d8b920cbe5c4753085189780635xContent-Type: text/plain; charset="iso-8859-1"Content-Transfer-Encoding: 7bit--==Multipart_Boundary_xa7bb2d8b920cbe5c4753085189780635xContent-Type: application/x-msdownload;name="extraction.xls"Content-Disposition: attachment;filename="extraction.xls"Content-Transfer-Encoding: base64CiAKIAogCiAKCiAKbG9naWQJdGRhdGUJdHRpbWUJc3J2aWQJcHJvdHlwZQlkZWF0aWxzCWFjdGlvbglhdHNzCXN3Zm0Jb3MJdHQJcmVtYXJrcwkKIjEiCSIyMDA2LTA3LTA3IgkiMTU6MTI6NDkiCSJzZGxhOSIJImNwdSIJIjkxIgkic2VydmVyIHN0YWZmIGluZm9ybWVkIgkiYWN0aW9uIHRha2VuIgkicmVzbG92ZWQiCSJvayIJIjciCSJvayIKIjIiCSIyMDA2LTA3LTA3IgkiMTc6NDk6MjMiCSJzZGxhNyIJImNwdSIJIjgyIgkic2VydmVyIHN0YWZmIGluZm9ybWVkIgkiYWN0aW9uIHRha2VuIgkibm90IHJlc2xvdmVkIgkib2siCSIyNSIJIm9rIgoiMyIJIjIwMDYtMDctMDciCSIxODoxNDoyNiIJInNkbGE3IgkiY3B1IgkiMTAwIgkic2VydmVyIHN0YWZmIGluZm9ybWVkIgkiYXV0byByZWNvdmVyeSIJinfact 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:<?php//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)); fclose($file); // 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" . "--{$mime_boundary}--\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>"); }?> Quote Link to comment https://forums.phpfreaks.com/topic/14382-any-expert-comment-on-big-problrm/ Share on other sites More sharing options...
kenrbnsn Posted July 12, 2006 Share Posted July 12, 2006 Take a look at PHPmailer at http://phpmailer.sourceforge.net/This class makes sending attachments very easy.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14382-any-expert-comment-on-big-problrm/#findComment-56755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.