Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

My PHP Form Does Not Show Errors But I Do Not Receive Email When It Is Filled

Guest
Aug 02, 2011 Aug 02, 2011

Hi,

This form used to work.  I tested it and received emails in all email boxes.

But now it does not work.  Nobody know why, including the programmer.

http://www.collegestudentvoice.com/form/form.php

Emails work, No Spam Filter Set, Emails are White Listed

Value of Parameter Match Email Prefixes

Dreamweaver101.1

here is another file used by the form.  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\">";
  }
?>

ANOTHER FILE;    SEND-FORM

<?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>

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2011 Aug 02, 2011

You mean it was working before and stopped suddenly? I guess if it works fine that time, then let us know what changes have you made recently. It will help to resolve your problem

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 02, 2011 Aug 02, 2011
LATEST

the form did not work for most email in the Label  "College Sports"'

the values of the parameters did not agree with email prefixes.

(i.e., was  _college@collegestudentvoice.net  --->> @collegestudentvoice.net)

This is the only thing that i changed

The form was test from a different PC and also did not work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines