I am combining an email feedback form and the image uploader that I had programmed awhile back.
I have everything working except I need the email to state whether there was an upload. Help! I've tried everything I can think of and keep getting an error.
So, here's the code of result1.php:
PHP Code:
<?php
$datetime = date("l dS of F Y H:i:s");
$message = "On $datetime\n";
$message .= "<br />Here are the details of the form submission:\n";
while (list($key, $val) = each($_POST)) {
if ($key == 'redirect') {
$redirect = $val;
}
if (($key != 'redirect') and ($key != 'recipient')) {
$val = trim($val);
$message .= "<br />$key: $val\n";
}
}
/*
A function to upload a file.
@param $index - form field index (int)
@param $is_small - bool value to indicate that this is a small file
@return bool true if ok & error message in the case of error
*/
function ProcessUploadedFile($index, $is_small) {
global $s_path, $b_path;
$msg = '';
if ($is_small) {
$prefix = 's';
$path = $s_path;
}
if ($_FILES[$prefix.'_userfile'.$index]['size'] > 0) {
if ($_FILES[$prefix.'_userfile'.$index]['size'] > 10485760) { //10MB
$msg = "Your uploaded file size is more than 10MB so please reduce the file size and then upload";
} else {
if (($_FILES[$prefix.'_userfile'.$index]['type'] != 'image/pjpeg') && ($_FILES[$prefix.'_userfile'.$index]['type'] != 'image/gif')) {
$msg = "Your uploaded file must be of JPG or GIF. Other file types are not allowed.";
} else {
if (move_uploaded_file($_FILES[$prefix.'_userfile'.$index]['tmp_name'], $path.$_FILES[$prefix.'_userfile'.$index]['name']) === false) {
$msg = "Failed to move uploaded file";
}
}
}
} else $msg = "There was no picture selected";
if ($msg == '') return true;
else return $msg;
}
$s_path = "incoming/"; //path to save small images
for ($i = 1; $i < 4; $i++) { //cycle for small images
$result = ProcessUploadedFile($i, true);
if ($result !== true) {
echo ' ';
} else {
echo 'Your image was uploaded successfully!</br>';
}
}
$lcval = strtolower($val);
$pos = strpos($lcval,"http://");
//Genesis' code//
$ServerName = $_SERVER["HTTP_HOST"];
$message .= "<br /> Site: $ServerName \n";
$visitorip = $_SERVER['REMOTE_ADDR'] ;
$message .= "<br /> IP: $visitorip\n";
//validation
if (strlen($_POST['name']) <1)
{
echo 'Please enter your name';
exit;
}
if (strlen($_POST['name']) >50)
{
echo 'Your name exceeds 50 characters.';
exit;
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $_POST['vis_email']))
{
echo 'Please enter a valid e-mail address';
exit;
}
if (strlen($_POST['vis_email']) == 0 )
{
echo 'Please enter a valid e-mail address';
exit;
}
/*ANTISPAM WEBSITES*/
if (ereg('[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
{
echo 'Please do not enter html or script tags in the comment section of your testimonial.';
exit;
}
if (strlen($_POST['comments']) > 255 )
{
echo 'Please do not enter more than 255 characters in the comment section of your testimonial.';
exit;
}
//anti-spam
if (strlen($_POST['sum']) == 0 )
{
echo 'Please answer anti-spam questions.';
exit;
}
if (strlen($_POST['sum']) > 1 )
{
echo 'Please answer anti-spam questions.';
exit;
}
if (! ereg('[4]', $_POST['sum']))
{
echo 'Please answer anti-spam questions.';
exit;
}
$vis_email = $_POST['vis_email'] ;
//Format Email
$email = "my email address in here";
$subject = "Testimonial Form";
$headers = "From: $vis_email\r\n";
$headers .= "Content-type: text/html\r\n";
//Send Email
mail($email,$subject,$message,$headers);
?>
Here's the image upload portion of the form:
HTML Code:
<input name="s_userfile1" type="file" class="form" />
Thanks so much!!