Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,100 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,642 people online right now. Registration is fast and FREE... Join Now!




PHP Upload and then mail attachment

 
Reply to this topicStart new topic

PHP Upload and then mail attachment

brottmayer
23 Sep, 2007 - 08:12 AM
Post #1

D.I.C Head
**

Joined: 21 Jan, 2007
Posts: 67


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

CODE

<?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
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: PHP Upload And Then Mail Attachment
23 Sep, 2007 - 09:44 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
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)

smile.gif
User is online!Profile CardPM
+Quote Post

lse123
RE: PHP Upload And Then Mail Attachment
27 May, 2008 - 07:07 AM
Post #3

New D.I.C Head
*

Joined: 26 May, 2008
Posts: 5

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.ancientgreekdramainstitute-cyprus.org/apply.htm .
CODE
<?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);

?>

User is offlineProfile CardPM
+Quote Post

lse123
RE: PHP Upload And Then Mail Attachment
27 May, 2008 - 01:11 PM
Post #4

New D.I.C Head
*

Joined: 26 May, 2008
Posts: 5

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.ancientgreekdramainstitute-cypr...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):
CODE
<?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) ?

User is offlineProfile CardPM
+Quote Post

lse123
RE: PHP Upload And Then Mail Attachment
27 May, 2008 - 08:19 PM
Post #5

New D.I.C Head
*

Joined: 26 May, 2008
Posts: 5

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 ?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:46PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month