Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

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


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 05-22-2007, 06:41 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
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
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #2 (permalink)  
Old 05-23-2007, 01:12 AM
digiweb's Avatar
Contributing Member
 
Join Date: 04-07-06
Location: Manchester, NH
Posts: 722
iTrader: 1 / 100%
attach it to the outgoing email? like this?
 
Reply With Quote
  #3 (permalink)  
Old 05-23-2007, 01:22 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
Caroline.. thanks for the help..let me have a look at it and see if this will help.
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #4 (permalink)  
Old 05-23-2007, 10:30 AM
exam's Avatar
Senior Member
Latest Blog:
None

 
Join Date: 04-20-06
Posts: 278
iTrader: 0 / 0%
That looks good Caroline, I've also had success sending mail with this php class.
__________________
~exam~
 
Reply With Quote
  #5 (permalink)  
Old 05-23-2007, 10:48 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
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.
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #6 (permalink)  
Old 05-23-2007, 11:32 AM
exam's Avatar
Senior Member
Latest Blog:
None

 
Join Date: 04-20-06
Posts: 278
iTrader: 0 / 0%
Are the pdfs stored in the database or as files in the filesystem?
__________________
~exam~
 
Reply With Quote
  #7 (permalink)  
Old 05-23-2007, 11:44 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
Quote:
Originally Posted by exam View Post
Are the pdfs stored in the database or as files in the filesystem?
stored in a database which are uploaded by admin.
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #8 (permalink)  
Old 05-23-2007, 02:45 PM
exam's Avatar
Senior Member
Latest Blog:
None

 
Join Date: 04-20-06
Posts: 278
iTrader: 0 / 0%
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?
__________________
~exam~
 
Reply With Quote
  #9 (permalink)  
Old 05-23-2007, 10:06 PM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
exam.. the file name is stored in the database and the actual pdfs are stored in a folder called upload
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #10 (permalink)  
Old 05-24-2007, 12:19 AM
Contributing Member
Latest Blog:
None

 
Join Date: 05-06-07
Posts: 84
iTrader: 0 / 0%
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.
 
Reply With Quote
  #11 (permalink)  
Old 05-24-2007, 05:29 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
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!"); } ?>
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #12 (permalink)  
Old 05-24-2007, 11:46 PM
Contributing Member
Latest Blog:
None

 
Join Date: 05-06-07
Posts: 84
iTrader: 0 / 0%
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);
 
Reply With Quote
  #13 (permalink)  
Old 05-25-2007, 12:12 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
alainkun.. i will try it out and let u know. thanks
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #14 (permalink)  
Old 06-07-2007, 04:33 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
did not work

Quote:
Originally Posted by alainkun View Post
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);
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
  #15 (permalink)  
Old 06-07-2007, 05:33 AM
funguru's Avatar
Contributing Member
 
Join Date: 02-22-04
Posts: 1,029
iTrader: 4 / 100%
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
__________________
Add Link Directory $3.95 Submissions | FashionFlu.com Fashion Blog
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Email database brickred Marketing Forum 7 07-13-2004 10:29 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:11 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2014 Escalate Media




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.