By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

problem in sending email with attached file

P: 1
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given below.

function SendMail123($From,$FromName,$To,$ToName,$Subject,$ Text,$Html,$AttmFiles){

or die("neither text nor html part present.");
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
$From or die("sender address missing");
$To or die("recipient address missing");
$headers ="MIME-Version: 1.0\r\n";
$headers.="From: ".$FromName." <".$From.">\n";
$headers.="To: ".$ToName." <".$To.">\n";
$headers.="Reply-To: ".$FromName." <".$From.">\n";
$headers.="X-Priority: 1\n";
$headers.="X-MSMail-Priority: High\n";
$headers.="X-Mailer: My PHP Mailer\n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";
//Messages start with text/html alternatives in OB
$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
// html section
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
// end of IB
// attachments
if(count($AttmFiles) != 0){

foreach($AttmFiles as $AttmFile){
$patharray = explode ("/", $AttmFile);

$Msg.= "\n--".$OB."\n";
$Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
$Msg.="Content-Transfer-Encoding: base64\n";
$Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";

//file goes here
$fd= @fopen ($AttmFile, "r");
$FileContent= @fread($fd,filesize($AttmFile));
@fclose ($fd);
$FileContent=chunk_split(base64_encode($FileConten t));
//message ends

//syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");

if(isset($_POST['submit']) && $_POST['submit'] == 'Submit'){

$target_path = 'uploads/'.$_FILES['textDoc']['name'];

//system("chmod -R 777 ".$target_path);
if(move_uploaded_file($_FILES['textDoc']['tmp_name'], $target_path)) {


$message = $_POST["Comments"];
$HTML=$message ;
$ret = SendMail123(
$sender_email,$sender_emails, //sender
"","Recipients Name", //recipient
"PC - Free Assessment Form", //subject
$TEXT,$HTML,$ATTM); //body and attachment(s)


below is the email that i got....

From: <TEST123@TEST123.COM>
To: Recipients Name <>
Reply-To: <TEST123@TEST123.COM>
X-Priority: 1
X-MSMail-Priority: High
X-Mailer: My PHP Mailer
Content-Type: multipart/mixed;

This is a multi-part message in MIME format.

Content-Type: multipart/alternative;

Content-Type: text/plain;
Content-Transfer-Encoding: quoted-printable


Content-Type: text/html;
Content-Transfer-Encoding: base64



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



please help to get the actual file with attachment.
Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 801
I always used PHPMailer to send email attachment. See if this can help you.
Apr 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.