 |
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |

05-22-2007, 05:41 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
|
attach via database and email in php
i need some help with this.. i have a database stored with pdf files. The user will log in and then he will see a list of pdf files on his screen with a check box next to each, he would have an option to send 1 or multiple pdf files to an email address.
so what he does is ... check marks a pdf and then hits "send", this pop ups a box which will ask for an email address to which the email will be sent.
My problem is that i am not be able to attach the pdf which is checkmarked to the email..
can any one point me to the right direction?
thanks
|

05-23-2007, 12:12 AM
|
 |
Contributing Member
|
|
Join Date: 04-07-06
Location: Manchester, NH
Posts: 722
|
|
|
|

05-23-2007, 12:22 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
|
Caroline.. thanks for the help..let me have a look at it and see if this will help.
|

05-23-2007, 09:30 AM
|
 |
Senior Member
Latest Blog: None
|
|
Join Date: 04-20-06
Posts: 278
|
|
That looks good Caroline, I've also had success sending mail with this php class.
|

05-23-2007, 09:48 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
|
i will have a look at that to exam... the problem is that i am getting to attach the file to the email but when it is delivered. the file size is 0KB .. so i dont know whats going wrong with it.
|

05-23-2007, 10:32 AM
|
 |
Senior Member
Latest Blog: None
|
|
Join Date: 04-20-06
Posts: 278
|
|
|
Are the pdfs stored in the database or as files in the filesystem?
|

05-23-2007, 10:44 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
Quote:
Originally Posted by exam
Are the pdfs stored in the database or as files in the filesystem?
|
stored in a database which are uploaded by admin.
|

05-23-2007, 01:45 PM
|
 |
Senior Member
Latest Blog: None
|
|
Join Date: 04-20-06
Posts: 278
|
|
|
So the pdfs are stored as a binary blob? Or is the filename stored in the database, and the actual pdfs stored in a directory?
|

05-23-2007, 09:06 PM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
|
exam.. the file name is stored in the database and the actual pdfs are stored in a folder called upload
|

05-23-2007, 11:19 PM
|
|
Contributing Member
Latest Blog: None
|
|
Join Date: 05-06-07
Posts: 84
|
|
You have some examples to work with PHP and email in PHP official page:
http://jp.php.net/mail
You can see there examples about attach files.
|

05-24-2007, 04:29 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
Below is the php code i am using to attach...
Code:
<?php
$con = mysql_connect("localhost","xxxx","xxxx");
if (!$con)
{
die('Could not connect.');
}
mysql_select_db("inhealth_hospital", $con);
$res=mysql_query("select UserID from `patientmaster` where PatientID ='$pid'");
$row = mysql_fetch_array($res);
$res1=mysql_query("select File_Name from `patient_status_master` where PatientID ='$pid'");
$row1 = mysql_fetch_array($res1);
$fileatt = "./upload/"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $row1['File_Name']; // Filename that will be used for the file as the attachment
$email_from = $row['UserID']; // Who the email is from
$email_subject = "Sending a report.."; // The Subject of the email
$email_txt = "Please see the attached PDF."; // Message that the email has in it
$email_to = $_POST['em']; // Who the email is too
$headers = "From: ".$email_from;
$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\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= $_POST['tm'] . $email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_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";
$body = $_POST['tm'];
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
|

05-24-2007, 10:46 PM
|
|
Contributing Member
Latest Blog: None
|
|
Join Date: 05-06-07
Posts: 84
|
|
|
You told us you send the PDF files with 0kb size. Can you really recieve this email? I am, code really send a email?
I think you have to check some important think:
1- Check if you are able to send email WITHOUD add .pdf.
2- Check you .pdf route is really correct.
3- Try code with :
mail($email_to, $email_subject, $email_message, $headers);
instand of:
@mail($email_to, $email_subject, $email_message, $headers);
|

05-24-2007, 11:12 PM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
|
alainkun.. i will try it out and let u know. thanks
|

06-07-2007, 03:33 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
did not work
Quote:
Originally Posted by alainkun
You told us you send the PDF files with 0kb size. Can you really recieve this email? I am, code really send a email?
I think you have to check some important think:
1- Check if you are able to send email WITHOUD add .pdf.
2- Check you .pdf route is really correct.
3- Try code with :
mail($email_to, $email_subject, $email_message, $headers);
instand of:
@mail($email_to, $email_subject, $email_message, $headers);
|
|

06-07-2007, 04:33 AM
|
 |
Contributing Member
|
|
Join Date: 02-22-04
Posts: 999
|
|
i narrowed down the proble to this code
[code
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
[/code]
the code is able to read the file name... but not the file size coz when i get the email, the file name shows as attached in the email but the size is 0kb..
the whole code for the php email script can be found here. http://apptools.com/phptools/forms/forms5.php
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Email database
|
brickred |
Marketing Forum |
7 |
07-13-2004 09:29 PM |
All times are GMT -7. The time now is 12:28 PM.
© Copyright 2010 V7 Inc Powered by vBulletin Copyright © 2000-2010 Jelsoft Enterprises Limited.
|
|
|