14 Replies - 4472 Views - Last Post: 12 January 2011 - 01:36 AM Rate Topic: -----

#1 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 07:09 PM

Form doesn't send uploaded photo to my email as expected!

Here's my code which seems to work perfectly with one exception - when I go to my email address to look for the file, it's not there. What am I doing wrong! HELP!!!!


<?php
$target = "files/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$to = "[email protected]";   
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.";
}
echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";
?>

This post has been edited by CTphpnwb: 06 January 2011 - 08:24 PM
Reason for edit:: Added CODE TAGS!!!


Is This A Good Question/Topic? 0
  • +

Replies To: Form doesn't send uploaded photo to my email as expected!

#2 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 07:59 PM

The code you posted isn't responsible for sending email, it just moves the uploaded file to another directory of your server. Show the code for sending email, so that we can review whats wrong.
Was This Post Helpful? 2
  • +
  • -

#3 creativecoding   User is offline

  • Hash != Encryption
  • member icon


Reputation: 931
  • View blog
  • Posts: 3,216
  • Joined: 19-January 10

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 08:01 PM

Nowhere does it send to your email.

Add this after "the file has been uploaded"


$link = $target . basename($_FILES['uploaded']['name'];
$message = "An image has been uploaded. Here is the link: " . $link;
mail($to, 'Image uploaded!', $message);


Was This Post Helpful? 1
  • +
  • -

#4 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 08:55 PM

Still need help! Doesn't work after I added the new code. Here's what I got now:

<?php
$target = "files/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$to = "[email protected]";   
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
$link = $target . basename($_FILES['uploaded']['name'];  
$message = "An image has been uploaded. Here is the link: " . $link;  
mail($to, 'Image uploaded!', $message); 

else {
echo "Sorry, there was a problem uploading your file.";
}
echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";
?>


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 07 January 2011 - 04:18 AM

Was This Post Helpful? 0
  • +
  • -

#5 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 09:40 PM

You can use PEAR package Mail_Mime for sending mail with attachments easily. Take a look at the link below to have an idea about how it works.

Mail_Mime Example

After you have successfully uploading the image with the following code-

<?php
$target = "files/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$to = "[email protected]";   
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.";
}
echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";
?>



In the code block where you have echoed out "file is uploaded", add the code for sending mail as shown in the link. Try and if you have any problem , let us know with what happens.
Was This Post Helpful? 1
  • +
  • -

#6 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 10:42 PM

Thank you a million times! I finally received an email from this code at my email address. My final problem is that there was no attachment. My file didn't make it. Appreciate your suggestions.

Here's code I'm using now:

<?php  
$target = "files/";  
$target = $target . basename( $_FILES['uploaded']['name']) ;  
$ok=1;  
$to = "[email protected]";     
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  
{  
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";  
}  
include('Mail.php');
include('Mail/mime.php');

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/upload/upload.php';
$crlf = "\n";
$hdrs = array(
              'From'    => '[email protected]',
              'Subject' => 'Test mime message'
              );

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('[email protected]', $hdrs, $body);

echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";  
?>


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 07 January 2011 - 04:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 11:02 PM

$file = '/upload/upload.php';



Above line you should check carefully. Are you trying to send upload.php as attachment? and is the file upload.php really exists in the directory?

From your code, it seems you are trying to upload an image. First make sure you have successfully uploaded the image in the directory. Then locate to the exact file path of the image to the $file variable.
Was This Post Helpful? 1
  • +
  • -

#8 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 11:11 PM

In reference to $file = '/upload/upload.php';

Oops! This is the location where my php file is. I will change it to reflect the image file. But, how do I do that? This is a form that my visitors will be using to upload an image from their hard drive through the form to my email address.
Was This Post Helpful? 0
  • +
  • -

#9 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 06 January 2011 - 11:25 PM

You are moving file to a sub-directory named "file"

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} 



But check the above code, as you have used two different input name, "uploaded" & "uploadedfile", which should be identical and the name you used in your html form. After correcting that error, check if the file is actually moved or not. If its working, means moved to file/ directory, then, the path of the image file you just uploaded will be-

$file="file/".$_FILES['uploaded']['name'];



which is same as variable $target in this case.
Was This Post Helpful? 1
  • +
  • -

#10 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 07 January 2011 - 12:21 AM

I can't figure this php code out!!! It's placing the files in the correct directory on my server. The email stuff is working now. But for some reason, I just can't get any attachments to go to my email address: Here's what I've got now:

<?php  
$file="file/".$_FILES['uploaded']['name'];
$target = "files/";  
$target = $target . basename( $_FILES['uploaded']['name']) ;  
$ok=1;  
$to = "[email protected]";     
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  
{  
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";  
}  
include('Mail.php');
include('Mail/mime.php');

$text = 'Text version of email';
$html = '<html><body>Attached is photo uploaded for your cookie order.</body></html>';
$file = '/upload/upload.php';
$crlf = "\n";
$hdrs = array(
              'From'    => '[email protected]',
              'Subject' => 'Order for Photo Cookies'
              );

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('[email protected]', $hdrs, $body);

echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";  
?>


I just noticed that I have the email address incorrect at this line:

$to = "[email protected]";

But when I corrected it to

$to = "[email protected]";

It didn't seem to make any difference. The file still didn't go to my email address.

Thanks again!

I get the email, but no attachment.

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 07 January 2011 - 04:19 AM

Was This Post Helpful? 0
  • +
  • -

#11 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 07 January 2011 - 12:26 AM

Make sure your file upload function is working properly. First comment out all the codes and put this code at top to check what happens-

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], "file/".$_FILES['uploaded']['name']))
{
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
} 

else
{
echo "Error occured:".$_FILES['uploaded']['error'];
}


This post has been edited by atik97: 07 January 2011 - 12:27 AM

Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 07 January 2011 - 04:19 AM

I've had to fix EVERY ONE of your posts, yrdixon. Please OBEY THE RULES and when posting code, do so IN CODE TAGS, as shown below!!!

:code:
Was This Post Helpful? 1
  • +
  • -

#13 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 07 January 2011 - 09:53 AM

Sorry about not following the rules! Please forgive me. I'll make sure I read them more thoroughly to conform.

Yvonne

View PostJackOfAllTrades, on 07 January 2011 - 10:19 AM, said:

I've had to fix EVERY ONE of your posts, yrdixon. Please OBEY THE RULES and when posting code, do so IN CODE TAGS, as shown below!!!

:code:

Was This Post Helpful? 0
  • +
  • -

#14 yrdixon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-January 11

Re: Form doesn't send uploaded photo to my email as expected!

Posted 07 January 2011 - 10:21 PM

I couldn't get that code to work at all! I guess I'm too much of a novice with php. I found one that does almost everything I want with these exceptions:

1. The sender's name is 'Apache' instead of the expected actual sender's name.

2. Instead of getting the sender's email, I get 'Apache [[email protected]]'

3. The attachment is an unknown file type 'bin' instead of the image file that was sent. (My code calls for jpg, jpeg, or gif image file types.)

Here's my code:

<?php 
$fileatt = "/upload/upload.php"; // Path to the file 
$fileatt_type = "jpg, jpeg, gif"; // File Type 
$fileatt_name = ""; // Filename that will be used for the file as the attachment 

$email_subject = "Order for Photo Cookies"; // The Subject of the email 
$email_txt = "Attached is customer's uploaded photo for their cookie order."; // Message that the email has in it 

$email_to = "[email protected]"; // Who the email is too 

$headers = "From: ".$email_from; 

$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 .= "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" . 
$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"; 

$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!"); 
} 
echo "<meta http-equiv='refresh' content='0;url=http://www.jroyaltreats.com/thankyou.htm'>";  
?>


Was This Post Helpful? 0
  • +
  • -

#15 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Form doesn't send uploaded photo to my email as expected!

Posted 12 January 2011 - 01:36 AM

Here is an example of how to send mail with attachment-

<?php
include('Mail.php');
include('Mail/mime.php');

$html = '<html><body>HTML version of email</body></html>';
$file = '/path/to/file/yourFile.txt';
$crlf = "\n";
$hdrs = array(
              'From'    => '[email protected]',
              'Subject' => 'Test mime message'
              );

$mime = new Mail_mime($crlf);

$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('[email protected]', $hdrs, $body);
?> 



First make sure this code works for you and you are getting mail with attachment. Don't forget to set exact path of your file. If it works, then try to add this piece of code with your file uploading functionality. In that case, you need one more change to this code, which is to set proper mime type of your file.

After implementing this, if you still face any problem, let me know.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1