Results 1 to 6 of 6

Thread: Send auto reply to form field email address

  1. #1
    Join Date
    Dec 2008
    Posts
    20
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Send auto reply to form field email address

    How do I write php to read the email from a form and send the auto reply to the user who filled in their email address in the form in php?
    This is the script I am Using.
    At present it sends the data to me from the form and shows me the users e-mail addredd who filled it in and displays the thank-you page, but it also sends me the auto reply.
    Here is my script

    <?php
    $to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" );
    $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
    $name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ;
    $headers = "From: $from";
    $subject = "Members Data From R.......com";

    $fields = array();
    $fields{"Member_Name"} = "Members Name";
    $fields{"Email"} = "Members Email Address";
    $fields{"....."} = "......";

    $body = " You have received...:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    $headers2 = "From: me@somewhere.com";
    $subject2 = "Thank-you for ..";
    $autoreply = "Somebody from... Thank-you";

    if($from == '') {print "You have..";}
    else {
    if($name == '') {print "You have..";}
    else {
    $send = mail($to, $subject, $body, $headers);
    $send2 = mail($from, $subject2, $autoreply, $headers2);
    if($send){header( "Location: http://www.r....com/r../thankyou.html" );}
    else
    {print "We encountered ...@.....com"; }
    }
    }
    ?>

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    On the first look, I think it's:
    Code:
    $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
    ...which needs to be changed into Email
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    stealthmode666 (12-11-2008)

  4. #3
    Join Date
    Dec 2008
    Posts
    20
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Thanks, I will try this in a few mins and see what happens

  5. #4
    Join Date
    Dec 2008
    Posts
    20
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Hi there, got a page of errors on submit:
    I changed the line below to what you suggested on the next line but got an error:
    $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
    $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ;

    Notice: Undefined index: homeowner in E:\domains\r\r....com\user\htdocs\r....\sform.php on line 170
    plus about 15 more of these.

    Warning: mail() [function.mail]: SMTP server response: 554 <me@r.........com>: Recipient address rejected: Relay access denied in E:\domains\r\r.......com\user\htdocs\r.......\sform.php on line 182
    We encountered an error sending your mail, please notify webmaster@r......com

    This is line 182 on my script:
    $send = mail($to, $subject, $body, $headers);

    Thanks for trying to help

  6. #5
    Join Date
    Dec 2008
    Posts
    20
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Somehow the script is sending the form and the auto-reply to the same email.
    I have used my email just now to send the form but it will be changed to the persons email of which it needs to go when all is working.
    Do I need to add another variable that takes the form persons email which will send the auto-reply to them?
    Not very good at php and really struggling with this one.

    The form on submit I put a hidden field in which is this:
    <input name="sendto" type="hidden" id="sendto" value="me@someone.com" />
    I have used .js validation on server-side to check form before it can be submitted.

    On my form this is the email input box of which I want the .php script to send the auto-reply to:
    <input name="Email" type="text" id="Email" size="50" />
    Hope this helps

  7. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    1. Know your mail server

    2. Go to php.ini and set your mail server to that of the response on the first bullet. Alternatively, you can set it via ini_set():
      PHP Code:
      ini_set('SMTP','your_smtp_protocol_here'); // Set your SMTP server 
    3. Know your SMTP port. Usually, the default is 25, but no harm when you ask.

    4. Set it on your php.ini, or alternatively, do the same:
      PHP Code:
      ini_set('smtp_port','25'); // Set your smtp port number 


    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •