SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Washington DC
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple autoreplies

    Hi!

    I am trying to configure the basic upload script so that it sends out two separate autoreplies: one to us with the attachment, and one to the person who filled out the form confirming receipt of the attachment. I thought I'd scripted it properly, but the second (confirmation) autoreply does not send. Can anyone tell me where I screwed up?

    PHP Code:
        // remove escape characters from POST array
        
    if (PHP_VERSION && get_magic_quotes_gpc()) {
          function 
    stripslashes_deep($value) {
            
    $value is_array($value) ? array_map('stripslashes_deep'$value) : stripslashes($value);
            return 
    $value;
            }
          
    $_POST array_map('stripslashes_deep'$_POST);
          }

        
    // List the expected fields
        
    $expected = array('to''from''subject''sender''email''cover''fileatt');
        
    // Set the required fields
        
    $required = array('to',  'from''sender''email''cover''fileatt');
        
    // Create an empty array for any missing fields
        
    $missing = array();
        
        
    //assume that there is nothing suspect
        
    $suspect false;
        
    //Create a pattern to locate suspect phrases
        
    $pattern '/Content-Type:|Bcc:|CC:/i';
        
    // function to check for suspect phrases
        
    function isSuspect($val$pattern$suspect) {
        
    // if the variable is an array, loop through each element
        // and pass it recursively back to the same function
        
    if (is_array($val)) {
          foreach (
    $val as $item) {
            
    isSuspect($item$pattern$suspect);
            }
          }
        else {
          
    // if one of the suspect phrases is found, set Boolean to true
          
    if (preg_match($pattern$val)) {
            
    $suspect true;
            }
          }
        }
        
      
    // check the $_POST array and any subarrays for suspect content
      
    isSuspect($_POST$pattern$suspect);

      if (
    $suspect) {
        
    $mailSent false;
        unset(
    $missing);
      } else {
        
    // process the $_POST variables
        
    foreach ($_POST as $key => $value) {
          
    // assign to temporary variable and strip whitespace if not an array
          
    $temp is_array($value) ? $value trim($value);
          
    // if empty and required, add to $missing array
          
    if (empty($temp) && in_array($key$required)) {
            
    array_push($missing$key);
          } elseif (
    in_array($key$expected)) {
            
    // otherwise, assign to a variable of the same name as $key
            
    ${$key} = $temp;
          }
        }
      }
      
      
    // validate the email address
      
    if (!empty($email)) {
        
    // regex to identify illegal characters in email address
        
    $checkEmail '/^[^@]+@[^\s\r\n\'";,@%]+$/';
        
    // reject the email address if it doesn't match
        
    if (!preg_match($checkEmail$email)) {
          
    $suspect true;
          
    $mailSent false;
          unset(
    $missing);
        }
      }
      
      
    // go ahead only if not suspect and all required fields OK
      
    if (!$suspect && empty($missing)) {
        
        
    // Obtain file upload vars
        
    $fileatt      $_FILES['fileatt']['tmp_name'];
        
    $fileatt_type $_FILES['fileatt']['type'];
        
    $fileatt_name $_FILES['fileatt']['name'];
        
        
    $headers "From: $from";
        
    $body =    "Great News!!\r\n\r\n$sender has submitted a resume for our open position of: $subject.\r\n\r\nHere is the cover letter:\r\n\r\n" $cover "\r\n\r\n";
        
    $body wordwrap($body70);
        
    $headers2 "From: noreply@foo.bar";
        
    $autoreply "Thank you for submitting your resume and expressing interest in Foobar!\r\n\r\n";
        
    $autoreply .= "Due to the volume of applications that we receive, it is not possible to respond to all applicants individually. Successful candidates will be contacted within two weeks of application through the contact information you provided. However, if you are qualified and the position you are applying for has been filled up, we will keep you in our active list for three months and notify you when the need for the position arises. If you do not hear from us within a week, your application was not selected for the position.\r\n\r\n";
        
    $autoreply .= "We wish you every personal and professional success with your job search and in the future.\r\n\r\n";
        
    $autoreply .= "Thank you, again, for your interest in our company.\r\n\r\n";
        
    $autoreply .= "Foobar\r\nHuman Resources Department";
        
        if (
    is_uploaded_file($fileatt)) {
          
    // Read the file to be attached ('rb' = read binary)
          
    $file fopen($fileatt,'rb');
          
    $data fread($file,filesize($fileatt));
          
    fclose($file);
        
          
    // Generate a boundary string
          
    $semi_rand md5(time());
          
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
          
          
    // Add the headers for a file attachment
          
    $headers .= "\nMIME-Version: 1.0\n" .
                      
    "Content-Type: multipart/mixed;\n" .
                      
    " boundary=\"{$mime_boundary}\"";
        
          
    // Add a multipart boundary above the plain message
          
    $message "This is a multi-part message in MIME format.\r\n\r\n" .
                     
    "--{$mime_boundary}\n" .
                     
    "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
                     
    "Content-Transfer-Encoding: 7bit\r\n\r\n" 
                     
    "Great News!!\r\n\r\n$sender has submitted a resume for our open position of: $subject.\r\n\r\nHere is the cover letter:\r\n\r\n" $cover "\r\n\r\n";
        
          
    // Base64 encode the file data
          
    $data chunk_split(base64_encode($data));
        
          
    // Add file attachment to the message
          
    $message .= "--{$mime_boundary}\n" .
                      
    "Content-Type: {$fileatt_type};\r\n" .
                      
    " name=\"{$fileatt_name}\"\r\n" .
                      
    "Content-Disposition: attachment;\r\n" .
                      
    " filename=\"{$fileatt_name}\"\r\n" .
                      
    "Content-Transfer-Encoding: base64\r\n\r\n" .
                      
    $data "\n\n" .
                      
    "--{$mime_boundary}--\r\n";
                      
        }
        
    // Send the message
        
    if ($suspect) {
            
    $ok false;
            unset (
    $missing);
        }
        else {
        if (!
    $suspect && empty($missing)) {
            
    $ok mail($to$subject$message$headers);
            if (
    $ok) {
                
    // redirect to the "Thank You" page and send the autoreply
                
    header('Location:rsm_thanks.php');
                
    $reply  mail($sender$subject$autoreply$from);
                unset(
    $missing);
            } 
        }
        }
      } 

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Try sending the mail first and then redirect?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Washington DC
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Try sending the mail first and then redirect?
    I moved the $reply line ahead of the header() line-- no change.
    I moved it completely out of the "if($ok)" loop, up a level-- still no change.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Ok, so something in the parameters might be wrong. Try echoing them and see what they contain.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Washington DC
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Ok, so something in the parameters might be wrong. Try echoing them and see what they contain.
    Not sure I quite understand what you are suggesting. But here is what I did do:

    I replaced:

    header('Location:rsm_thanks.php');
    $reply = mail($sender, $subject, $autoreply, $from);

    with

    echo $sender, $subject, $autoreply, $from;

    It printed across the top of the page. It did show me that I used one wrong parameter: $sender should have been $email--replaced that, but still no go!

    It seems that the mail function is not working--

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    But it works for the other mail you send, just a couple of lines of code earlier?
    What's the difference between the two? Just the receiver email address? Then maybe it's getting caught in the spam filter?

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Washington DC
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    But it works for the other mail you send, just a couple of lines of code earlier?
    What's the difference between the two? Just the receiver email address? Then maybe it's getting caught in the spam filter?
    Well, I used my work email address in the script and my home email address in the form. I checked the spam folder of my home email address and the confirmation was not there--not even a day later.

    Before I go asking my sysadmin to start checking the smtp server-- y'all are sure that my code is legit?

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Washington DC
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyway--

    I just put an autoresponder in my website's control panel. I am beginning to think that the mail() function can only be instantiated once.

  9. #9
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TMacFarlane View Post
    I just put an autoresponder in my website's control panel. I am beginning to think that the mail() function can only be instantiated once.
    To test your theory, why not comment out the first mail() instance and see if it sends to the second?

    If you can't instantiate the mail() function twice (which seems odd), try putting the reply in rsm_thanks.php and see if it works, OR you could look into Swift Mailer and use SMTP.

  10. #10
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also noticed $from isn't set anywhere. That could be causing your problem. of course, as guido said, put the mail function before the redirect or it won't work.


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
  •