4 Replies - 73533 Views - Last Post: 27 May 2008 - 09:19 PM Rate Topic: -----

#1 brottmayer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 21-January 07

PHP Upload and then mail attachment

Post icon  Posted 23 September 2007 - 09:12 AM

I am using the following coding (which I believe is the right file to use to upload a document to a file):

<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/pdf")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>



Now what I want to do is to take this file the has been uploaded to the file 'upload' and email it to an email address. Any help would be greatly appreciated. Thank you.

brottmayer

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Upload and then mail attachment

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4309
  • View blog
  • Posts: 12,088
  • Joined: 18-April 07

Re: PHP Upload and then mail attachment

Posted 23 September 2007 - 10:44 AM

The link I have posted below shows you an example of doing exactly this. It shows you how to take an uploaded form, construct a multi-part mime encoded email to include the attachment and send it through PHP mail() function. My suggestion to you would be to construct a nice PHP object that will allow people to easily make an email and attach files to it. Once you construct something like that you could then easily store it away in your archive of useful tidbits and use it for other projects.

Anyways, enjoy the site (scroll down towards the bottom to see the code).

Advanced email in PHP (Sitepoint)

:)
Was This Post Helpful? 1

#3 lse123  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 68
  • Joined: 26-May 08

Re: PHP Upload and then mail attachment

Posted 27 May 2008 - 08:07 AM

I read link:
Advanced email in PHP (Sitepoint) below
but I have a question:
If I code as it says the attachment will come as a file icon to click on, and open the appropriate application ?
How in a php processed form (whereas I include a file Field), email come has in email message body a php webpage(with code like <?= $email ?>) & attached the doc or jpg file as icon(to click the file open the Word or FireWorks) ?

In the second question I do the former(php webpage: confirm-apply-si.php) with below code, how I do the later ?
Form is at http://www.ancientgr...s.org/apply.htm .
<?php
// session_start(); // start up your PHP session! 
/* recipients */
// $to = "lse@world-marketinghome.com"; 
// $to = "info@polis-index.com.cy"; 
$subject = "Apply for the Professional Session www.ancientgreekdramainstitute-cyprus.org"; 
$radiobutton = $_POST['radiobutton'];
$title = $_POST['title'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone_day = $_POST['phone_day1'];
$phone_evening = $_POST['phone_evening1'];
$country = $_POST['country'];
$message = $_POST['message'];

$fax = $_POST['fax'];
$address = $_POST['address'];
$city = $_POST['city'];
$cv = $_POST['cv'];

$to = "info@ancientgreekdramainstitute-cyprus.org,ancientgreekdramainstitute@yahoo.com,{$email}";   // info@polis-realestate.eu 

// --------------------------------------
include_once ("confirm-apply-si.php"); 

ob_start();
include('confirm-apply-si.php');
$message = ob_get_clean();
/*
ob_start();
include('confirm-contactus.php');
$message_customer = ob_get_clean();
*/
$headers = "From:info@ancientgreekdramainstitute-cyprus.org";					 
// $headers .= "\nBcc:info@Polis-RealEstate.eu"
$headers .= "\nReply-To:info@ancientgreekdramainstitute-cyprus.org"; 
$headers .= "\nContent-Type: text/html; charset=UTF-8";
$headers .= "\nMIME-Version: 1.0";  

// mail($email,$subject,$message_customer,$headers); 

mail($to,$subject,$message,$headers); 

?>


Was This Post Helpful? 0
  • +
  • -

#4 lse123  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 68
  • Joined: 26-May 08

Re: PHP Upload and then mail attachment

Posted 27 May 2008 - 02:11 PM

At last I make it to send email attachment of submited file with an included file php as message body, but after three tries and success emails with attachments came, NOW come an email only with nothing in , reads as:
"
-----Original Message-----
From: tid123akh76@p3slh141.shr.phx3.secureserver.net [mailto:tid123akh76@p3slh141.shr.phx3.secureserver.net]
Sent: Tuesday, May 27, 2008 11:55 PM
To: info@ancientgreekdramainstitute-cyprus.org; ancientgreekdramainstitute@yahoo.com; lse@world-marketinghome.com
Subject: Apply for the Professional Session www.ancientgreekdramainstitute-cyprus.org

"
you may try at http://www.ancientgr...rg/apply-mf.htm to come to you the email rather than one with attachment(to the email you insert in form)...
form processor(apply-iti-processor2.php):
<?php
// session_start(); // start up your PHP session! 
/* recipients */
// $to = "lse@world-marketinghome.com"; 
// $to = "info@polis-index.com.cy"; 
$subject = "Apply for the Professional Session www.ancientgreekdramainstitute-cyprus.org"; 
$radiobutton = $_POST['radiobutton'];
$title = $_POST['title'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone_day = $_POST['phone_day1'];
$phone_evening = $_POST['phone_evening1'];
$country = $_POST['country'];
$message3 = $_POST['message'];

$fax = $_POST['fax'];
$address = $_POST['address'];
$city = $_POST['city'];
// $cv = $_POST['fileatt'];
//$cv = $fileatt_name;
// Obtain file upload vars
$fileatt	  = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];



$to = "info@ancientgreekdramainstitute-cyprus.org,ancientgreekdramainstitute@yahoo.com,{$email}";   // info@polis-realestate.eu 

// --------------------------------------
//include_once ("confirm-apply-si.php"); 
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
  include_once ("confirm-apply-si.php"); 
} else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
ob_start();
include('confirm-apply-si.php');
$message2 = ob_get_clean();
/*
ob_start();
include('confirm-contactus.php');
$message_customer = ob_get_clean();
*/
$headers = "From:info@ancientgreekdramainstitute-cyprus.org";					 
// $headers .= "\nBcc:info@Polis-RealEstate.eu"
$headers .= "\nReply-To:info@ancientgreekdramainstitute-cyprus.org"; 
// $headers .= "\nContent-Type: text/html; charset=UTF-8";
// $headers .= "\nMIME-Version: 1.0";  
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/html; charset=\"iso-8859-1\"\n" .
			 "Content-Transfer-Encoding: 7bit\n\n" .
			 $message2 . "\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";
}
// mail($email,$subject,$message_customer,$headers); 

// mail($to,$subject,$message,$headers); 
// Send the message

?>



how I print to the confirm form submission screen(php file INCLUDED) the name and directory of the submitted file in visitor's PC(URL) ?
Was This Post Helpful? 0
  • +
  • -

#5 lse123  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 68
  • Joined: 26-May 08

Re: PHP Upload and then mail attachment

Posted 27 May 2008 - 09:19 PM

problem fixed, one last point...
how I print to the confirm form submission screen(php file INCLUDED <?= $fileField; ?>) the name and directory of the submitted file in visitor's PC(URL) ?
I can send any file size as attachment ? how I set max limit (attached file) ? To send any file type, I do not refer to individual files just leave it simple, just this ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1