Hey Guys, Im having a problem with adding an attachment to a form and sending it through email... This is what I get when I press submit
The website encountered an error while retrieving http://webaddress/eddies/form-to-email.php. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
heres the code
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
$email = $_POST["email"];
$firstName = $_POST["firstName"];
$surname = $_POST ["surname"];
//Get the uploaded file information
//get the file extension of the file
strrpos($name_of_uploaded_file, '.') + 1);
$_FILES["uploaded_file"]["size"]/1024;//size in KBs
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("doc", "docx", "pdf", "txt");
if($size_of_uploaded_file > $max_allowed_file_size )
$errors .= "\n Size of file should be less than $max_allowed_file_size";
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++)
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
$allowed_ext = true;
$errors .= "\n The uploaded file is not supported file type. ".
" Only the following file types are supported: ".implode(',',$allowed_extensions);
//copy the temp. uploaded file to uploads folder
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
$errors .= '\n error while copying the uploaded file';
echo "Name and email are mandatory!";
echo "Bad email value!";
$email_from = $email;//<== update the email address
$email_subject = "New Applicant";
$email_body = " details about email".
$to = "firstname.lastname@example.org";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
//done. redirect to thank-you page.
// Function to validate against any email injection attempts
$injections = array('(\n+)',
$inject = join('|', $injections);
$inject = "/$inject/i";
Once I press submit I can see the file being uploaded but then the server error comes up.
Anyone see a problem with it?