Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: I want to auto generate an email to user from a form

  1. #1
    Join Date
    Dec 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I want to auto generate an email to user from a form

    Hey all, was wondering if anyone knew code that I can place within my form that'll automatically generate an email to the user once he/she fills out my online form?

    I have my form currently set up to generate an email to me that provides me with the user's form info, but would like to automatically send the user an email to thank them for submitting the form.

    Does anyone know any simple code that can do the trick?

    Thanks so much...

    Joe

  2. #2
    Join Date
    Jun 2008
    Posts
    40
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    This is simply done: use the mail function.

    It works as thus:

    mail(string to, string subject, string body, (additional headers), (additional parameters))

  3. #3
    Join Date
    Dec 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for responding...I'm very new to php, any chance you can post the proper code for me?

    Here is my current form code:
    PHP Code:
    <?php // Option $Explicit; ?>
    <?php 
    // ------------- SET DATABASE CONNECTION -------------------   ?>
    <?php 
    include ("variables.php"?>
    <?php 
    // ------------- SET SQL  -------------------   ?>
    <?php
    $contact_table
    ="contacts";
    mysql_connect($host,$user,$password);
    mysql_select_db($database);

    function 
    mktime_from_mysqldate($mysqldate) {
      
    $break explode(" "$mysqldate);
      
    $datebreak explode("-"$break[0]);
      
    $time explode(":"$break[1]);
      return 
    mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]);
    }
    function 
    sbad($text)
    {
        
    $textaddslashes($text);
        
    $textmysql_real_escape_string($text);
        
    $textstrip_tags($text);
        return 
    $text;    
    }



    if(
    $_POST["posted"]==1) {
        if(
    eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$_POST['email'])) { 
           
    $salutation=sbad($_POST["Salutation"]);
           
    $email=sbad($_POST["email"]);
           
    $fname=sbad($_POST["First"]);
           
    $lname=sbad($_POST["Last"]);
           
    $title=sbad($_POST["Job_Title"]);
           
    $company=sbad($_POST["Company"]);
           
    $address_1=sbad($_POST["Address_1"]);
           
    $address_2=sbad($_POST["Address_2"]);
           
    $city=sbad($_POST["City"]);
           
    $state=sbad($_POST["State"]);
           
    $zip=sbad($_POST["Zip"]);
           
    $country=sbad($_POST["Country"]);
           
    $phone=sbad($_POST["Phone"]);
           
    $cell=sbad($_POST["Cell"]);
           
    $fax=sbad($_POST["Fax"]);
           
    $mailinglist=sbad($_POST["Mailing_List"]);
           
    $remove=sbad($_POST["Remove"]);
           
    $comment=sbad($_POST["Comment"]);
           
    $SUCert=sbad($_POST["Su_class_want"]);
           
    $ISC2certhave=sbad($_POST["ISC2have"]);
              
    $ISACAcerthave=sbad($_POST["ISACAhave"]);
              
    $SANScert=sbad($_POST["SANShave"]);       
           
    $QSA=sbad($_POST["QSAcheck"]);
           
    $QPTL=sbad($_POST["QPTLcheck"]);
           
    $QEH=sbad($_POST["QEHcheck"]);       
           
    $QEP=sbad($_POST["QEPcheck"]);    
           
    $QFE=sbad($_POST["QFEcheck"]);                  
           
    $CISA=sbad($_POST["cert_in_CISA"]);
           if (
    $remove=="Yes")
              
    $flag="REMOVE FROM MAILING LIST";
              
           
    $email ereg_replace("\n","",$email);
           
    $fname ereg_replace("\n","",$fname);
           
    $lname ereg_replace("\n","",$lname);
           
    $mailtext="$flag \n Contact from: $salutation $fname $lname \n $email\n Position: $title \n Company: $company \n Phone: $phone Cell: $cell Fax: $fax";
           
    $mailtext.="\nAddress: \n $address_1 \n $address_2 \n $city,$state $zip $country \n Comments:\n $comment";
            
    $mailtext.="\nWants to be added to mailing list? $mailinglist\n";
            
    $mailtext.="CISSP Cert? $CISSP\nGIAC Cert? $GIAC\nCISA Cert? $CISA";
            
    #formmail mailtext format
            
    $now=date("l dS o F Y h:i:s A");    
            
    $mailtext="Below is the result of your feedback form.\nIt was submitted by $email on: $now\n\n---------------------------------------------\n\nSalutation: $salutation\n\nFirst: $fname\n\nLast: $lname\n\nJob Title: $title \n\nCompany: $company\n\nAddress_1: $address_1\n\nAddress_2: $address_2\n\nCity: $city\n\nState: $state\n\nZip Code: $zip\n\nCountry: $country\n\nDirect Line: $phone\n\nCell: $cell\n\nFax: $fax\n\nSu_class_want: $SUCert\n\nISC2have: $ISC2certhave\n\nISACAhave: $ISACAcerthave\n\nSANShave: $SANScert\n\nComment: $comment\n\n---------------------------------------------";
            
            
            
    $webmaster_addr 'MY EMAIL ADDRESS GOES HERE';
            
    #send a quick mail to webmaster
            
            
    mail("MY EMAIL ADDRESS GOES HERE","EMAIL SUBJECT GOES HERE",$mailtext,"From: $email\nReply-to: $email");
            
            
    #prep sql query
            
    $sql="INSERT INTO $contact_table ";
            
    $sql.="(RegTime,Salutation,First_Name,Last_Name,Job_Title, Company, Address_1,Address_2,City,State,Zip";
            
    $sql.=",Country,Phone,Cell_Phone,Fax,Email,Mailing_List,Remove,Comments,CISSP,GIAC,CISA) VALUES ";
            
    $sql.=" ('".date("Y-n-j H:i:s")."','$salutation','$fname','$lname','$title','$company','$address_1','$address_2'";
            
    $sql.=",'$city','$state','$zip','$country','$phone','$cell','$fax','$email','$mailinglist','$remove','$comment'";
            
    $sql.=",'$CISSP','$GIAC','$CISA');";
            
    #print $sql;
            #drop into db
            
    if (!($res mysql_db_query($database$sql))) {
                
    $err mysql_error(); 
               
    #something bad happened
                
    mail("MY EMAIL ADDRESS GOES HERE","Database error in events_win9mo.php","Error: $err\nValues: $values_str","From: $webmaster_addr");
            } 
            include(
    "THANK YOU PAGE URL GOES HERE");       
        }
    } else {
        
    ?>
    THANKS, MUCH APPRECIATED!

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Thats a template you have to put your info into. At MY EMAIL ADDRESS GOES HERE and put in your actual email address like john@gmail.com or whatever your actual address is also at EMAIL SUBJECT GOES HERE put what you want the subject of the email to be. Also THANK YOU PAGE URL GOES HERE.

  5. #5
    Join Date
    Dec 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the reply...yeah, I know that I have to put in my info in those spots, I was asking if someone can give me the code for an auto email response so that when a user fills out the form, he/she will be sent an email from me.

    Can anyone give me that code?

    Thanks,
    Joe

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    oo
    $sendata="Your blah blah blah was received.";
    $send ="Thank You for your blah blah blah blah"
    $yada = "Thank You";
    mail( $email, $yada, $sendata, $send);

  7. #7
    Join Date
    Dec 2007
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok, so all I have to do is drop the following code somewhere between my "<php" and "?>"


    $sendata="Your information was received.";
    $send ="Thank You for your information"
    $yada = "Thank You";
    mail( $email, $yada, $sendata, $send);



    Thanks for the help,
    Joe

  8. #8
    Join Date
    Oct 2007
    Posts
    53
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    Below is a quick example for E-mailing a message with PHP, if you want to send an auto responder for doing some action, it would work on the same principles. When the user does something (if(isset($varName())) then you will email the message, though with a predefined message, subject, and From header in your PHP so that it isn't in your HTML.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>My E-mail Script</title>
    <style>
    .width {
    	width:800px;
    }
    </style>
    </head>
    
    <body>
    PHP Code:
    <?php
    if(isset($_POST['submit']))
    // If the user submited the E-mail, do this.
        
    mail($_POST['recipient'], $_POST['subject'], $_POST['body'], 'From: '.$_POST['sender']); // E-mail the message.
    // End if.
    else
    // Display the form to send the E-mail.
    ?>
    HTML Code:
    <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
    <input name="recipient" type="text" class="width" value="E-mail address of recipient..."  maxlength="30"  />
    <input name="sender" type="hidden" value="noreply@mydomain.com" /><br />
    <input name="subject" type="text" class="width" value="Subject of E-mail..."  maxlength="30" /><br />
    <textarea name="body" rows="25" class="width">Type the body of your E-mail here.</textarea><br />
    <input name="submit" type="submit" value="E-mail the message" />
    </form>
    PHP Code:
    <?php
    // End else.
    ?>
    HTML Code:
    </body>
    </html>
    Last edited by AmenKa; 11-10-2008 at 07:40 PM.

  9. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    umm I think mine is the simple way of doing it. And yes the way you asked above the post above this one is right. This will send at the same time the user submits the form both emails will be sent, one to you the other to them.

  10. #10
    Join Date
    Oct 2007
    Posts
    53
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    Indeed I agree, but he doesn't seem to understand how the mail function works... I hope he can look at my example and figure it out better... I won't write what he wants for him, I would rather he use another example to figure it out himself...

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
  •