Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Send email - confirm recieved.

    Hi,

    I am relativley new to PHP and I have a email form script that I need some help with.

    It is a simple form which people fill in fields and it then once they click submit it send the form off to an email address inserted within the external php file.

    The thing I want to do is add in an extra feature so when some one clicks submit, an email also sends off to the person who filled in the form saying thank you for your email etc. etc.

    Here is my php code for the form:

    Code:
    <?php
    
    $my_email = "test@test.co.uk";
    
    $continue = "/";
    
    $errors = array();
    
    // Remove $_COOKIE elements from $_REQUEST.
    
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    
    // Build message.
    
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    
    $message = build_message($_REQUEST);
    
    $message = stripslashes($message);
    
    $subject = "Free Consultation";
    
    $subject = stripslashes($subject);
    
    $from_name = "";
    
    if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
    
    $headers = "From: {$from_name} <{$_REQUEST['email']}>";
    
    mail($my_email,$subject,$message,$headers);
    
    ?>
    If anyone would know how I would implement this I would be most grateful.

    Regards,

    Paul

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    At the least an "auto response email" allows spam bot scripts to send nuisance emails to any address they put into the email field. At best (because your code is not validating what was entered) it allows a spam bot script to send anything to anyone it wants.

    Just display a "thank you" message on the web page (the visitor is already on your site with their browser open) and please add some validation to the form data to help stop spamming through your mail server.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I know about this, I am trying to do it for some one who I am doing some work for. I did explian this to them but they insisted they have the feature, do you know how it can be achieved?

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by jpopuk View Post
    Hi,

    I am relativley new to PHP and I have a email form script that I need some help with.

    It is a simple form which people fill in fields and it then once they click submit it send the form off to an email address inserted within the external php file.

    The thing I want to do is add in an extra feature so when some one clicks submit, an email also sends off to the person who filled in the form saying thank you for your email etc. etc.

    Here is my php code for the form:

    Code:
    <?php
    
    $my_email = "test@test.co.uk";
    
    $continue = "/";
    
    $errors = array();
    
    // Remove $_COOKIE elements from $_REQUEST.
    
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    
    // Build message.
    
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    
    $message = build_message($_REQUEST);
    
    $message = stripslashes($message);
    
    $subject = "Free Consultation";
    
    $subject = stripslashes($subject);
    
    $from_name = "";
    
    if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
    
    $headers = "From: {$from_name} <{$_REQUEST['email']}>";
    
    mail($my_email,$subject,$message,$headers);
    
    ?>
    If anyone would know how I would implement this I would be most grateful.

    Regards,

    Paul
    How bout this...

    Code:
    $message = "Thank You for your submission";
    
    $subject = "Consultation Received";
    
    $headers = "From: {$from_name} <{$my_email}>";
    
    mail($_REQUEST['email'],$subject,$message,$headers);
    Unless i'm missing something that should work if you just add it on to the end of your script.

    If you want to make it so that it checks if the e-mail was received you would need to add something so that it checks your e-mail and searches for the value of $_REQUEST['email']

  • Users who have thanked zackwiny for this post:

    jpopuk (08-12-2008)

  • #5
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hey, that works a treat. Thank you very much. The one thing I would say about this is, with the
    Code:
    {$from_name}
    . Will the email be from the name entered in the name field?

  • #6
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    No, That would be your name I assume so you would have:
    PHP Code:
    $from_name 'Automatic mailer';
    $my_email 'noreply@yoursite.com';
    $headers "From: {$from_name} <{$my_email}>"
    Hope this helps you
    Last edited by Webmonkey; 08-12-2008 at 08:55 PM.


  •  

    Posting Permissions

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