473,511 Members | 15,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem in sending email with attached file

1 New Member
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){
$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundery_001";

$Html=$Html?$Html:preg_replace("/\n/","{br}",$Text)
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");
$Html=stripslashes($Html);
$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.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n\n";
// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_split(base64_encode($Html))."\n\n";
// end of IB
$Msg.="\n--".$IB."--\n";
// attachments
if(count($AttmFiles) != 0){

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

$FileName=$patharray[count($patharray)-1];
$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));
$Msg.=$FileContent;
$Msg.="\n\n";
}
}
//message ends
$Msg.="\n--".$OB."--\n";
mail($To,$Subject,$Msg,$headers);

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

if(isset($_POST['submit']) && $_POST['submit'] == 'Submit'){
//die("hhhhhhhh");
$ATTM=array();
@chmod('uploads/',777);

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

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

$ATTM[]=$target_path;

}
$message = $_POST["Comments"];
$TEXT=$message;
$HTML=$message ;
$sender_email=$_POST['txtEmail'];
$ret = SendMail123(
$sender_email,$sender_emails, //sender
"aaaaa@gmail.com","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 <aaaaa@gmail.com>
Reply-To: <TEST123@TEST123.COM>
X-Priority: 1
X-MSMail-Priority: High
X-Mailer: My PHP Mailer
Content-Type: multipart/mixed;
boundary="----=_OuterBoundary_000"


This is a multi-part message in MIME format.

------=_OuterBoundary_000
Content-Type: multipart/alternative;
boundary="----=_InnerBoundery_001"


------=_InnerBoundery_001
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

test123


------=_InnerBoundery_001
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: base64

dGVzdDEyMw==




------=_InnerBoundery_001--

------=_OuterBoundary_000
Content-Type: application/octetstream;
name="val1.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="val1.txt"

MTE2MDY3Mzg1NQ==




------=_OuterBoundary_000--




please help to get the actual file with attachment.
Apr 26 '07 #1
1 3479
mwasif
802 Recognized Expert Contributor
I always used PHPMailer to send email attachment. See if this can help you.
Apr 26 '07 #2

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

Similar topics

1
3125
by: Agenzia Petracca | last post by:
i wanna send html files (even *.doc) in the body of a mail with this code: <? $userfile = "file.html"; $fp = fopen($userfile, "r"); $file = fread($fp, filesize($userfile)); $file =...
7
1801
by: a c s | last post by:
Hello, I'm a php newbie and have been using the following php code fine (until now) to submit a form and create an email message. I recently moved the site from a local server to an ISP's server...
4
8642
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
0
1064
by: Mike Grace | last post by:
Hi, I am writing a web site which sends order confirmations to users via email. Two changes that are needed are as follows: 1) PDF files are going to be attached to the email. It could be...
5
2795
by: Nick Z. | last post by:
When using SmtpClient and sending a message with an attached file using SendAsync(...), if I add File.Delete(pathToAttachedFile) in the SendCompleted event handler I get a file in use exception. Is...
2
846
by: Andy_Khosravi | last post by:
I posted this question about two days ago, but for some reason it never actually got put up. I couldn't' find it with searches, so I am re-posting it now. I apologize if this is a double post. ...
4
9056
by: Seguros Catatumbo | last post by:
Hi guys, i am having trouble deleting a file after sending an email. The file is in use. Here's the code: String texto = "Test"; System.Net.Mail.SmtpClient smtp = new...
11
6627
jamesd0142
by: jamesd0142 | last post by:
'server address Dim client As New SmtpClient("imap.uk.aol.com", 143) 'username and password client.Credentials = New Net.NetworkCredential("my username", "mypassword") ...
28
4394
tdw
by: tdw | last post by:
Hi all, I am trying to add a feature to our database that automates sending emails. When entering a new order, I want the option to send an email to the company the order came from, attaching a...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.