image upload 2 form send prob
Posted: Fri Dec 12, 2003 8:59 pm
I am posting again as I got told off for "Hijacking a thread".
I have a real problem with this!
The first part of the script works perfectly, (it might not be brilliant code but it does what I want) which is to upload an image, show it and then post a form which asks for the usual, who to ?, who from?, email... etc.
Then I have another page of code that sends the image, which supposedly works fine, I get the message "Mail sent! Yay PHP!", but in my email nothing, yes I recieve the mail but there's nothing there.
Now all I need to know is what and where do I need to put into this code so that it works, thank you?
Now that I've formulated the question properly I might get an answer!!!
upload.php
send.php many thanks to Bech100 for this well formulated script!!!
I have a real problem with this!
The first part of the script works perfectly, (it might not be brilliant code but it does what I want) which is to upload an image, show it and then post a form which asks for the usual, who to ?, who from?, email... etc.
Then I have another page of code that sends the image, which supposedly works fine, I get the message "Mail sent! Yay PHP!", but in my email nothing, yes I recieve the mail but there's nothing there.
Now all I need to know is what and where do I need to put into this code so that it works, thank you?
Now that I've formulated the question properly I might get an answer!!!
upload.php
Code: Select all
<?php
$action = $_POST["action"];
$max_size = "1048576"; // Max size in BYTES (1MB)
echo "
//javascript and stylesheet here
<form action='$PHP_SELF' method=post name=f enctype='multipart/form-data' onsubmit="return check();">
<input type='file' name='filename' accept='image/jpg'>
<input type='hidden' name='action' value='upload'>
<input type='submit' value='Upload File'><br>
Image File jpg(max size: $max_size bytes/".($max_size/1024)." kb)
</form><br>
<DIV class=end></DIV>";
if ($action == 'upload')
{
if ($_FILES["filename"]["size"] > $max_size) die ("<b>File too big! Try again...</b>");
copy($_FILES["filename"]["tmp_name"],"./".$_FILES["filename"]["name"]) or die("<b>Choose an image!!!</b>");
echo "<b>File Uploaded.</b><br>"; // for debug --> $filename --> ".$destination."/".$filename_name."</h2>";
echo "temp file: $filename_name<br>\n"; //$filename = temp_name : $filename_name = original_name
echo "<br>\n";
echo "<img src=./$filename_name><br>\n";
echo "<DIV class=end></DIV><br>\n";
echo "<br>\n";
//form send now loads
echo "<FORM name='myform' ACTION='send.php' METHOD='POST'>\n";
echo "Email To : <INPUT TYPE='TEXT' NAME='email_t'><br>\n";
echo "Your ForeName: <INPUT TYPE='TEXT' NAME='name'><br>\n";
echo "Your Surname: <INPUT TYPE='TEXT' NAME='surname'><br>\n";
echo "Your Email: <INPUT TYPE='TEXT' NAME='email_f'><br>\n";
echo "Subject: <INPUT TYPE='TEXT' NAME='subject' value'Oh Goddess'><br>\n";
echo "Message: <textarea name='message' rows='10' cols='40'></textarea>\n";
//echo "<INPUT TYPE='hidden' NAME='$filename_name'><br>\n";
echo "<INPUT TYPE='SUBMIT' VALUE='Send' NAME='sendit'>\n";
echo "<INPUT TYPE='SUBMIT' VALUE='Cancel' NAME='cancelit'><br>\n";
echo "</form>\n";
echo "<br>\n";
echo "<br>\n";
}
?>Code: Select all
<?php
// Read POST request params into global vars
$to = $_POST['email_t'];
$from = $_POST['email_f'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Obtain file upload vars
$fileatt = $_FILES['filename']['tmp_name'];
$fileatt_type = $_FILES['filename']['type'];
$fileatt_name = $_FILES['filename']['name'];
$headers = "From: $from";
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/plain; charset="iso-8859-1"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\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";
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>