Results 1 to 2 of 2

Thread: Upload & email form processor

  1. #1
    rlhanson's Avatar
    rlhanson is offline Master Glow Jedi
    Join Date
    Aug 2007
    Location
    Chapman, Kansas
    Posts
    531

    Default Upload & email form processor

    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($itrue);
     if (
    $result !== true) {
      echo 
    '&nbsp;';
     } 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']) == )
    {
    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']) == )
    {
    echo 
    'Please answer anti-spam questions.';
    exit;
    }
    if (
    strlen($_POST['sum']) > )
    {
    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!!
    Thank you,
    Lynne Hanson
    RL Hanson-Online

  2. #2
    rlhanson's Avatar
    rlhanson is offline Master Glow Jedi
    Join Date
    Aug 2007
    Location
    Chapman, Kansas
    Posts
    531

    Default

    Here's the solution that worked for me:

    On the upload form:
    HTML Code:
     <input name="s_userfile1" type="file" id="image" class="form" onchange="document.getElementById('imageName').value=this.value;" size="25" maxlength="50" />
            <input name="upload" type="hidden" id="imageName" class="form" />
    On the form processor:
    PHP Code:
    <?php
    $vis_email 
    $_POST['vis_email'] ;
    $image $_POST['imageName'] ;
    //Format Email
    $email    "my email address here";
    $subject  "Testimonial Form";
    $headers  "From: $vis_email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $upload .= "$image";
    //Send Email
    mail($email,$subject,$message,$headers,$upload);
    ?>
    Thank you,
    Lynne Hanson
    RL Hanson-Online

Similar Threads

  1. Form Processor - ereg
    By rlhanson in forum Programming Talk
    Replies: 9
    Last Post: 08-12-2008, 06:17 PM
  2. Form Processor - multiple recipients
    By rlhanson in forum Programming Talk
    Replies: 9
    Last Post: 05-30-2008, 08:18 AM
  3. Form Processor issues
    By rlhanson in forum Programming Talk
    Replies: 21
    Last Post: 08-16-2007, 12:50 PM
  4. Frontpage email form address from field
    By monkette in forum General Support
    Replies: 1
    Last Post: 02-20-2005, 08:59 PM
  5. Replies: 0
    Last Post: 01-18-2005, 04:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16