php contact form - any ideas how to add an autoresponder to this one?

bamme

Senior Member
Hi All

I'm really rubbish at php. Straight up. Heh. Web designing, i often come across contact forms but this one (in a wordpress theme, would prefer to keep this form) I'm struggling to see how/where to add something that will send a quick email on Submit, to the email address inputted in the form field, just saying "Thanks for your email.. We'll be in touch soon.." or similar. The code is here:

Code:
[COLOR=#000000] [COLOR=#0000BB]<?php          [/COLOR][COLOR=#007700]if(isset([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'submit'[/COLOR][COLOR=#007700]])) {          [/COLOR][COLOR=#0000BB]error_reporting[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]E_NOTICE[/COLOR][COLOR=#007700]);          function [/COLOR][COLOR=#0000BB]valid_email[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$str[/COLOR][COLOR=#007700])          {          return ( ! [/COLOR][COLOR=#0000BB]preg_match[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$str[/COLOR][COLOR=#007700])) ? [/COLOR][COLOR=#0000BB]FALSE [/COLOR][COLOR=#007700]: [/COLOR][COLOR=#0000BB]TRUE[/COLOR][COLOR=#007700];            }          if([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'name'[/COLOR][COLOR=#007700]]!=[/COLOR][COLOR=#DD0000]'' [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'email'[/COLOR][COLOR=#007700]]!=[/COLOR][COLOR=#DD0000]'' [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]valid_email[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'email'[/COLOR][COLOR=#007700]])==[/COLOR][COLOR=#0000BB]TRUE [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'comment'[/COLOR][COLOR=#007700]])>[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700])          {              [/COLOR][COLOR=#0000BB]$to [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]preg_replace[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"([\r\n])"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]hexstr[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'receiver'[/COLOR][COLOR=#007700]]));              [/COLOR][COLOR=#0000BB]$from [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]preg_replace[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"([\r\n])"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'email'[/COLOR][COLOR=#007700]]);              [/COLOR][COLOR=#0000BB]$subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"Website contact message from "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'name'[/COLOR][COLOR=#007700]];              [/COLOR][COLOR=#0000BB]$message [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'comment'[/COLOR][COLOR=#007700]];              [/COLOR][COLOR=#0000BB]$match [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"/(bcc:|cc:|content\-type:)/i"[/COLOR][COLOR=#007700];                if ([/COLOR][COLOR=#0000BB]preg_match[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$match[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$to[/COLOR][COLOR=#007700]) ||                    [/COLOR][COLOR=#0000BB]preg_match[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$match[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$from[/COLOR][COLOR=#007700]) ||                    [/COLOR][COLOR=#0000BB]preg_match[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$match[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$message[/COLOR][COLOR=#007700])) {                  die([/COLOR][COLOR=#DD0000]"Header injection detected."[/COLOR][COLOR=#007700]);                }              [/COLOR][COLOR=#0000BB]$headers [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"From: "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$from[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]"\r\n"[/COLOR][COLOR=#007700];                [/COLOR][COLOR=#0000BB]$headers [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#DD0000]"Reply-to: "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$from[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]"\r\n"[/COLOR][COLOR=#007700];        if([/COLOR][COLOR=#0000BB]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$to[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$message[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$headers[/COLOR][COLOR=#007700]))              {                  echo [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]//SUCCESS              [/COLOR][COLOR=#007700]}              else {                  echo [/COLOR][COLOR=#0000BB]2[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]//FAILURE - server failure              [/COLOR][COLOR=#007700]}          }          else {            echo [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]//FAILURE - not valid email          [/COLOR][COLOR=#007700]}          }else{            die([/COLOR][COLOR=#DD0000]"Direct access not allowed!"[/COLOR][COLOR=#007700]);          }            function [/COLOR][COLOR=#0000BB]hexstr[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$hexstr[/COLOR][COLOR=#007700]) {                  [/COLOR][COLOR=#0000BB]$hexstr [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]str_replace[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]' '[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]''[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$hexstr[/COLOR][COLOR=#007700]);                  [/COLOR][COLOR=#0000BB]$hexstr [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]str_replace[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'\x'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]''[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$hexstr[/COLOR][COLOR=#007700]);                  [/COLOR][COLOR=#0000BB]$retstr [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]pack[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'H*'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$hexstr[/COLOR][COLOR=#007700]);                  return [/COLOR][COLOR=#0000BB]$retstr[/COLOR][COLOR=#007700];                }      [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR]

Can anyone tell me where and what to add here to give this php function a little autoresponder? Thanks so much. :)
 
Define a few extra variables
Code:
$to = preg_replace("([\r\n])", "", hexstr($_POST['receiver']));$from = preg_replace("([\r\n])", "", $_POST['email']);$subject = "Website contact message from ".$_POST['name'];$message = $_POST['comment'];$responseSubject = "Confirmation of your email";$responseMessage = "Thank you, we have received your email. This is what you sent: \n" . $_POST['comment'];

And use them to make a new mail function behind your success echo.
Code:
echo 1; //SUCCESSmail($from, $responseSubject, $responseMessage);

It should work but might need some tweaks. In all honesty though, I wouldn't send a confirmation email unless the visitor explicitly asks for it (by checking a checkbox for example).
 
Back
Top