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
Server error
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
Code:
<?php
include_once('Mail.php');
include_once('Mail_Mime/mime.php');
if(!isset($_POST['submit']))
{
//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
$name_of_uploaded_file =
basename($_FILES['uploaded_file']['name']);
//get the file extension of the file
$type_of_uploaded_file =
substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file =
$_FILES["uploaded_file"]["size"]/1024;//size in KBs
//Settings
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("doc", "docx", "pdf", "txt");
//Validations
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;
}
}
if(!$allowed_ext)
{
$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"];
if(is_uploaded_file($tmp_path))
{
if(!copy($tmp_path,$path_of_uploaded_file))
{
$errors .= '\n error while copying the uploaded file';
}
}
if(empty($email)||empty($firstName))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = $email;//<== update the email address
$email_subject = "New Applicant";
$email_body = " details about email".
$to = "email@email.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$message->addAttachment($path_of_uploaded_file);
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
Once I press submit I can see the file being uploaded but then the server error comes up.
Anyone see a problem with it?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
/home4/webcatc1/public_html/eddies/error_log:
[02-Sep-2012 14:03:43] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 115
[02-Sep-2012 14:06:19] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 115
[02-Sep-2012 16:32:16] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 115
[02-Sep-2012 16:34:36] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 116
[02-Sep-2012 17:32:20] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 156
[02-Sep-2012 17:40:40] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 156
[02-Sep-2012 17:40:50] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 156
[02-Sep-2012 17:41:36] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 148
[02-Sep-2012 17:46:49] PHP Fatal error: Call to undefined function addattachment() in /home4/webcatc1/public_html/eddies/form-to-email.php on line 83
[02-Sep-2012 17:58:13] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 187
[02-Sep-2012 18:03:11] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 188
[02-Sep-2012 18:06:11] PHP Fatal error: Call to undefined function addattachment() in /home4/webcatc1/public_html/eddies/form-to-email.php on line 41
[02-Oct-2012 16:42:33] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:42:33] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:42:41] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:42:41] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:43:12] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:43:12] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[02-Oct-2012 16:44:01] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 22
[02-Oct-2012 16:44:01] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 22
[02-Oct-2012 16:46:57] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:46:57] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:49:02] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:49:02] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:49:02] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 100
[02-Oct-2012 16:50:03] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:03] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 100
I would start by figuring out why the include is failing, as that failure may be causing at least some of the other errors. You might want to change those include()s to require()s since they appear to be mandatory.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
/home4/webcatc1/public_html/eddies/error_log:
[02-Oct-2012 16:49:02] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 100
[02-Oct-2012 16:50:03] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:03] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[02-Oct-2012 16:50:35] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 100
[03-Oct-2012 08:32:55] PHP Warning: include(Mail_Mime/mime.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[03-Oct-2012 08:32:55] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[03-Oct-2012 08:32:55] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 100
[03-Oct-2012 08:33:31] PHP Warning: require(Mail_Mime/mime.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[03-Oct-2012 08:33:31] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required 'Mail_Mime/mime.php' (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 3
[03-Oct-2012 08:39:05] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 89
[03-Oct-2012 08:39:05] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 89
[03-Oct-2012 08:39:05] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 99
[03-Oct-2012 08:46:46] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 86
[03-Oct-2012 08:46:46] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 86
[03-Oct-2012 08:46:46] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 96
[03-Oct-2012 08:52:26] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 92
[03-Oct-2012 08:53:43] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 08:53:43] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 08:53:43] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 96
[03-Oct-2012 09:09:55] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 190
[03-Oct-2012 09:11:44] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 191
[03-Oct-2012 09:12:08] PHP Parse error: syntax error, unexpected $end in /home4/webcatc1/public_html/eddies/form-to-email.php on line 191
[03-Oct-2012 09:16:10] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 09:16:10] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 09:16:10] PHP Fatal error: Call to undefined function isinjected() in /home4/webcatc1/public_html/eddies/form-to-email.php on line 81
[03-Oct-2012 09:49:46] PHP Warning: include_once(Mail_Mime/mime.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 09:49:46] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/form-to-email.php on line 4
[03-Oct-2012 09:49:46] PHP Fatal error: Call to a member function addAttachment() on a non-object in /home4/webcatc1/public_html/eddies/form-to-email.php on line 96
Well, your include of Mail_Mime/mime.php is still not working. You may either need to check/fix your include_path settings or else change it to use a full relative or absolute file path. Since it's not being included, that's probably why you get the "Call to a member function addAttachment() on a non-object" error.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
/home4/webcatc1/public_html/eddies/error_log:
[04-Oct-2012 04:56:18] PHP Warning: include_once() [<a href='function.include'>function.include</a>]: Failed opening '.:/usr/lib64/php:/usr/lib/php:/usr/share/pear/Mail_Mime/mime.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /home4/webcatc1/public_html/eddies/test.php on line 79
[04-Oct-2012 04:56:18] PHP Fatal error: Class 'Mail_mime' not found in /home4/webcatc1/public_html/eddies/test.php on line 83
You need to locate the files on your disk and point the include appropriately. Isn't much we could help with without knowing the exact location of the files you are wanting to include.
Bookmarks