Results 1 to 4 of 4

Thread: form mailer mod

  1. #1
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default form mailer mod

    i got this code to send email it works fine but i would like to do some mod but i dont have much knowledge to do it. when i send a message it just display a message, but i want it display a thank you page of my own. how can i do that?

    Code:
    function clean_input_4email($value, $check_all_patterns = true)
    {
     $patterns[0] = '/content-type:/';
     $patterns[1] = '/to:/';
     $patterns[2] = '/cc:/';
     $patterns[3] = '/bcc:/';
     if ($check_all_patterns)
     {
      $patterns[4] = '/\r/';
      $patterns[5] = '/\n/';
      $patterns[6] = '/%0a/';
      $patterns[7] = '/%0d/';
     }
     //NOTE: can use str_ireplace as this is case insensitive but only available on PHP version 5.0.
     return preg_replace($patterns, "", strtolower($value));
    }
    
    $name = clean_input_4email($_POST["name"]);
    $email = clean_input_4email($_POST["email"]);
    $thesubject = clean_input_4email($_POST["thesubject"]);
    $themessage = clean_input_4email($_POST["themessage"], false);
    
    $error_msg='ERROR - not sent. Try again.';
    
    $success_sent_msg='<p align="center"><strong>&nbsp;</strong></p>
                       <p align="center"><strong>Your message has been successfully sent to us<br>
                       </strong> and we will reply as soon as possible.</p>
                       <p align="center">A copy of your query has been sent to you.</p>
                       <p align="center">Thank you for contacting us.</p>';
    
    $replymessage = "Hi $name
    
    Thank you for your email.
    
    We will endeavour to reply to you shortly.
    
    Please DO NOT reply to this email.
    
    Below is a copy of the message you submitted:
    --------------------------------------------------
    Subject: $thesubject
    Query:
    $themessage
    --------------------------------------------------
    
    Thank you";
    
    // email variable not set - load $valid_ref1 page
    if (!isset($_POST['email']))
    {
     echo "<script language=\"JavaScript\"><!--\n ";
     echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
     exit;
    }
    
    $ref_page=$_SERVER["HTTP_REFERER"];
    $valid_referrer=0;
    if($ref_page==$valid_ref1) $valid_referrer=1;
    elseif($ref_page==$valid_ref2) $valid_referrer=1;
    if(!$valid_referrer)
    {
     echo "<script language=\"JavaScript\"><!--\n alert(\"$error_msg\");\n";
     echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
     exit;
    }
    $themessage = "name: $name \nQuery: $themessage";
    mail("$replyemail",
         "$thesubject",
         "$themessage",
         "From: $email\nReply-To: $email");
    mail("$email",
         "Receipt: $thesubject",
         "$replymessage",
         "From: $replyemail\nReply-To: $replyemail");
    echo $success_sent_msg;
    
    ?>

  2. #2
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I guess you need to add this line
    <input type=hidden name="redirect" value="yourdomain.com">

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not a pretty script, I'm afraid. The reliance upon Javascript is rather easy to avoid.
    Code:
    function clean_input_4email($value, $check_all_patterns = true)
    {
     $patterns[0] = '/content-type:/';
     $patterns[1] = '/to:/';
     $patterns[2] = '/cc:/';
     $patterns[3] = '/bcc:/';
     if ($check_all_patterns)
     {
      $patterns[4] = '/\r/';
      $patterns[5] = '/\n/';
      $patterns[6] = '/%0a/';
      $patterns[7] = '/%0d/';
     }
     //NOTE: can use str_ireplace as this is case insensitive but only available on PHP version 5.0.
     return preg_replace($patterns, "", strtolower($value));
    }
    
    $name = clean_input_4email($_POST["name"]);
    $email = clean_input_4email($_POST["email"]);
    $thesubject = clean_input_4email($_POST["thesubject"]);
    $themessage = clean_input_4email($_POST["themessage"], false);
    
    $error_msg='ERROR - not sent. Try again.';
    
    $success_sent_msg='<p align="center"><strong>&nbsp;</strong></p>
                       <p align="center"><strong>Your message has been successfully sent to us<br>
                       </strong> and we will reply as soon as possible.</p>
                       <p align="center">A copy of your query has been sent to you.</p>
                       <p align="center">Thank you for contacting us.</p>';
    
    $replymessage = "Hi $name
    
    Thank you for your email.
    
    We will endeavour to reply to you shortly.
    
    Please DO NOT reply to this email.
    
    Below is a copy of the message you submitted:
    --------------------------------------------------
    Subject: $thesubject
    Query:
    $themessage
    --------------------------------------------------
    
    Thank you";
    
    // email variable not set - load $valid_ref1 page
    if (!isset($_POST['email']))
    {
     header('Location: ' . $_POST['redirect'] || $valid_ref1);
     exit();
    }
    
    $ref_page=$_SERVER["HTTP_REFERER"];
    $valid_referrer=0;
    if($ref_page==$valid_ref1) $valid_referrer=1;
    elseif($ref_page==$valid_ref2) $valid_referrer=1;
    if(!$valid_referrer)
    {
     header('Location: ' . $_POST['redirect'] || $valid_ref1);
     exit();
    }
    $themessage = "name: $name \nQuery: $themessage";
    mail("$replyemail",
         "$thesubject",
         "$themessage",
         "From: $email\nReply-To: $email");
    mail("$email",
         "Receipt: $thesubject",
         "$replymessage",
         "From: $replyemail\nReply-To: $replyemail");
    echo $success_sent_msg;
    
    ?>
    Use a hidden form element with the name "redirect."
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how can i do that?
    oh one more thing. i would also like to know the ip add of the sender.

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
  •