Copy link to clipboard
Copied
Hi
http://www.collegestudentvoice.com/form/form.php
1. Programmer says there is no coding errors. Nothing has changed.
2. Host says there must be coding errors.
3. There may version incompetibilities with Perl script between the form and the host version.
these are 3 files:
Sendform:
<?php
// Pear library includes
// You should have the pear lib installed
include_once('Mail.php');
include_once('Mail/mime.php');
//Settings
$max_allowed_file_size = 10000000; // size in KB
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp");
$upload_folder = 'files/'; //<-- this folder must be writeable by the script
$your_email = 'tom@collegestudentvoice.com';//<<-- update this to your email address
$errors ='';
if(isset($_POST['submit']))
{
//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;
///------------Do Validations-------------
if(empty($_POST['name'])||empty($_POST['email']))
{
$errors .= "\n Name and Email are required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
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);
}
//send the email
if(empty($errors))
{
//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';
}
}
//send the email
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$text = "A user $name has sent you this message:\n $user_message";
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($path_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
//redirect to 'thank-you page
header('Location: thank-you.html');
}
}
///////////////////////////Functions/////////////////
// 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;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>File upload form</title>
<!-- define some style elements-->
<style>
label,a, body
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>
<?php
if(!empty($errors))
{
echo nl2br($errors);
}
?>
<form method="POST" name="email_form_with_php"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
<p>
<label for='name'>Name: </label><br>
<input type="text" name="name" >
</p>
<p>
<label for='email'>Email: </label><br>
<input type="text" name="email" >
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<p>
<label for='uploaded_file'>Select A File To Upload:</label> <br>
<input type="file" name="uploaded_file">
</p>
<input type="submit" value="Submit" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("email_form_with_php");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<noscript>
<small><a href='http://www.html-form-guide.com/email-form/php-email-form-attachment.html'
>How to attach file to email in PHP</a> article page.</small>
</noscript>
</body>
</html>
FORM:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>College Student</title>
<link rel="stylesheet" type="text/css" href="css/view.css" media="all">
<script type="text/javascript" src="js/view.js"></script>
<script src="js/forms.js" type="text/javascript"></script>
</head>
<body id="main_body" >
<div id="form_container">
<form action="formaction.php" method="post" enctype="multipart/form-data" name="contactus" id="contactus" style="border:none;" onsubmit="return validateForm()">
<div class="form_description">
<h2><img src="CSVlogo.GIF" width="269" height="97" alt="Logo" /></h2>
<p>Please type in your first and last names along with our school email address (i.e., yourname@ucla.edu) when submitting your articles or photographs.</p>
<p>Select the category that best describes the subject of your article or photograph. (i.e., Business, Politics, Sports, Humor, etc.)</p>
<p>When writing about a sporting event please include the name of the sport in the ‘Subject’ line of your email along with the date of the event and the names of the teams. (i.e., Basketball 01-15-11 L.A. Lakers vs.Detroit Pistons)</p>
</div>
<div>
<?php
if (isset($_GET['suc'])) {
echo "<div style='color:#F00; padding:15px; display:block; margin:10px 0 10px 0;'> ";
echo "Thank you for your submission!";
echo "</div>";
} else {
}
?>
</div>
<ul >
<li id="li_5" >
<label class="description" for="Business">Business </label>
<div>
<select class="element select medium" name="Business">
<option value="" selected="selected"></option>
<option value="Classified" >Classified</option>
<option value="careertips" >Career Tip</option>
</select>
</div>
</li> <li id="li_6" >
<label class="description" for="ProfessionalSports">Professional Sports </label>
<div>
<select class="element select medium" name="ProfessionalSports">
<option value="" selected="selected"></option>
<option value="NBA" >NBA</option>
<option value="NFL" >NFL</option>
<option value="MLB" >MLB</option>
<option value="otherprosports" >Other</option>
</select>
</div>
</li> <li id="li_7" >
<label class="description" for="Humor101">Humor 101</label>
<div>
<select class="element select medium" name="Humor101">
<option value="" selected="selected"></option>
<option value="Cartoons" >Cartoons</option>
<option value="Jokes" >Jokes</option>
<option value="Stories" >Stories</option>
<option value="Photographs" >Photographs</option>
</select>
</div>
</li> <li id="li_8" >
<label class="description" for="CollegeSports">College Sports</label>
<div>
<select class="element select medium" name="CollegeSports">
<option value="" selected="selected"></option>
<option value="basketballcollege" >Basketball</option>
<option value="baseballcollege" >Baseball</option>
<option value="Footballcollege" >Football</option>
<option value="Softball" >Softball</option>
<option value="othercollege" >Other</option>
</select>
</div>
</li> <li id="li_9" >
<label class="description" for="Politics">Politics</label>
<div>
<select class="element select medium" name="Politics">
<option value="" selected="selected"></option>
<option value="statelocal" >State/Local</option>
<option value="National" >National</option>
<option value="World" >World</option>
</select>
</div>
</li> <li id="li_1" >
<label class="description" for="element_1">Name </label>
<span>
<input id="First" name="First" class="element text" maxlength="255" size="40" value=""/>
<label>First</label>
</span>
<span>
<input id="Last" name= "Last" class="element text" maxlength="255" size="40" value=""/>
<label>Last</label>
</span>
</li>
<li id="li_sub" >
<label class="description" for="Subject">Subject </label>
<div>
<input id="Subject" name="Subject" class="element text medium required" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_2" >
<label class="description" for="Email">Email </label>
<div>
<input id="Email" name="Email" class="element text medium required email" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_3" >
<label class="description" for="EmailC">Confirm Email </label>
<div>
<input id="EmailC" name="EmailC" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_4" >
<label class="description" for="Suggestions">Suggestions </label>
<div>
<textarea id="Suggestions" name="Suggestions" class="element textarea medium"></textarea>
</div>
</li>
<li id="li_5" >
<label class="description" for="Upload">Upload File </label>
<input type="file" name="uploaded_file">
<div>
</div>
</li>
<li id="li_6" >
<label class="description" for="Upload">Are you human?</label>
<?php
require_once('recaptchalib.php');
$publickey = "6LfwwsISAAAAAA7UTKJcDATLiK-e55gPFW1Opfrq"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<div>
</div>
</li>
<li class="buttons">
<input type="submit" name="Submit" value="Submit" class="button" />
</li>
</ul>
</form>
<!-- <div id="footer">
</div>
--> </div>
</body>
</html>
FORMACTION
<?php
require_once('recaptchalib.php');
$privatekey = "6LfwwsISAAAAAAPShkJ6nV3qkgLDHCe2uXj9RTWw";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"");
}
else {
include_once('Mail.php');
include_once('Mail/mime.php');
$errors ='';
$max_allowed_file_size = 10000000; // size in KB
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp");
$upload_folder = 'files/';
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
$type_of_uploaded_file = substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
}
$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);
}
if(empty($errors))
{
$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';
}
}
$Business = Trim(stripslashes($_POST['Business']));
$ProfessionalSports = Trim(stripslashes($_POST['ProfessionalSports']));
$Humor101 = Trim(stripslashes($_POST['Humor101']));
$CollegeSports = Trim(stripslashes($_POST['CollegeSports']));
$Politics = Trim(stripslashes($_POST['Politics']));
$EmailToBusiness = $Business . "@collegestudentvoice.net";
$EmailToProfessionalSports = $ProfessionalSports . "@collegestudentvoice.net";
$EmailToHumor101 = $Humor101 ."@collegestudentvoice.net";
$EmailToCollegeSports = $CollegeSports . "@collegestudentvoice.net";
$EmailToPolitics = $Politics . "@collegestudentvoice.net";
$EmailTo = "narodetsky@yahoo.com";
$EMailSubject = Trim(stripslashes($_POST['Subject']));
$First = Trim(stripslashes($_POST['First']));
$Last = Trim(stripslashes($_POST['Last']));
$Email = Trim(stripslashes($_POST['Email']));
$Suggestions = Trim(stripslashes($_POST['Suggestions']));
$Body = "The following form has been filled";
$Body .= "\n";
$Body .= "---------------------------------------------------------------------------------";
$Body .= "\n";
$Body .= "\n";
$Body .= "First Name: ";
$Body .= $First;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $Last;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Business: ";
$Body .= $Business;
$Body .= "\n";
$Body .= "Professional Sports: ";
$Body .= $ProfessionalSports;
$Body .= "\n";
$Body .= "Humor 101: ";
$Body .= $Humor101;
$Body .= "\n";
$Body .= "College Sports: ";
$Body .= $CollegeSports;
$Body .= "\n";
$Body .= "Politics: ";
$Body .= $Politics;
$Body .= "\n";
$Body .= "Suggestions: ";
$Body .= $Suggestions;
$Body .= "\n";
$Body .= "\n";
$Body .= "---------------------------------------------------------------------------------\n";
$Body .= "Emails sent to: " . strtolower($EmailToBusiness) . " / " .strtolower($EmailToProfessionalSports). " / " .strtolower($EmailToHumor101). " / " .strtolower($EmailToCollegeSports). " / ".strtolower($EmailToPolitics). "";
$to = "kamran@radialcreations.com";
$subject= $EMailSubject;
$from = "do-not-reply@collegestudentvoice.com";
$text = "\n $Body";
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($path_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$Email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
if ($Business != "")
{
$mail->send(strtolower($EmailToBusiness), $headers, $body);
}
if ($ProfessionalSports != "")
{
$mail->send(strtolower($EmailToProfessionalSports), $headers, $body);
}
if ($Humor101 != "")
{
$mail->send(strtolower($EmailToHumor101), $headers, $body);
}
if ($CollegeSports != "")
{
$mail->send(strtolower($EmailToCollegeSports), $headers, $body);
}
if ($Politics != "")
{
$mail->send(strtolower($EmailToPolitics), $headers, $body);
}
}
print "<meta http-equiv=\"refresh\" content=\"0;URL=form.php?suc=y\">";
}
?>
That sounds like an expensive option just to get a PHP mail form to work! If there are no error messages, what exactly happens when you submit the form?does it redirect to a confirmation page but just doesn't send the mail? Does it simply reload the page, or hang and timeout?
Copy link to clipboard
Copied
Before I start reading through the files can you clarify if you recieve any errors on the server or from the script(s) and if so, where?
Copy link to clipboard
Copied
Hi,
There were no error from the server side or the scrip.
i decided to move my website to a dedicated server to eliminate the posibility the an update to a server of my original provider cause all the trouble.
Want to see that the form programmer will say now
Copy link to clipboard
Copied
Snakevez02
This is my update:
http://www.collegestudentvoice.com/form.php
Can Any Browser Setting Affect PHP form submission???
I moved my domain to my php develover server with a thought, as was suggested to me, that some software at my provider's server maybe interfering with the form.
!. I get confirmation that the form was submitted with No Errors.
2. When my developer fills the form, I receive ALL label into my email boxes.
When I fill a form from my laptop I Do Not get Any labels as emails. Zippo
cheers,
Dreamer101.1
Copy link to clipboard
Copied
http://www.collegestudentvoice.com/form.php
Copy link to clipboard
Copied
Also, you say that it no longer works which indicates it was working before. How long has it not been working? The reason I ask, is that sometimes it may be due to a temporary outage with the web host even when they swear there isn't. Or, they may have upgraded or patched something that they deny, or the person you talk to doesn't know about. I've encountered problems like this, wher I know for a fact nothing has changed in the code and it used to work. That simply means that something has changed on the server, even if only temporary.
Copy link to clipboard
Copied
Hi,
i moved my website to dedicated server to eliminate the posibility that you suggested.
thank you.
Copy link to clipboard
Copied
That sounds like an expensive option just to get a PHP mail form to work! If there are no error messages, what exactly happens when you submit the form?does it redirect to a confirmation page but just doesn't send the mail? Does it simply reload the page, or hang and timeout?
Copy link to clipboard
Copied
Lon,
http://www.collegestudentvoice.com/form.php
Can Any Browser Setting Affect PHP form submission???
I moved my domain to my php develover server with a thought, as was suggested to me, that some software at my provider's server maybe interfering with the form.
!. I get confirmation that the form was submitted with No Errors.
2. When my developer fills the form, I receive ALL label into my email boxes.
When I fill a form from my laptop I Do Not get Any labels as emails. Zippo
cheers,
Dreamer101.1
Copy link to clipboard
Copied
>Can Any Browser Setting Affect PHP form submission???
Sure. If the browser, firewall or any other component blocks the http referrer, and your script checks for a specific referrer, then it will fail.
>When I fill a form from my laptop I Do Not get Any labels as emails.
I don't know what this means. Labels as emails?
Copy link to clipboard
Copied
bregent,
you have explained everything was is happening.
Mine firewall setttings block the scrip so when I fill the form and submit it, I do not get any errors, but that form information does not go anywhere.
All firewall setting should be OFF when a form is submitted?
dreamweavewr101.1
Copy link to clipboard
Copied
>All firewall setting should be OFF when a form is submitted?
Not necessarily. It up to you. I have seen websites that do force users to turn off their firewalls and any other settings that may block the http referrer. These stes include a note and instructions to the visitor. I don't particularly like this route. I would rather disable referrer checking in your script, and use other methods to control abuse.
However, I don't know PHP so I can't tell you where in the script that you posted is the section to disable referrer checking. I didn't see anything obvious.
Copy link to clipboard
Copied
thank you for teaching me about referer.
now I know how to change its setting in my browser.
So will turn if OFF in firefox and see what happens
dreamer101.1
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more