Menu

MySQL and E-Mail

Help
John W.
2010-03-14
2013-06-03
  • John W.

    John W. - 2010-03-14

    I would like to have the form data e-mailed AND write to MySQL. Is it possible, and if so, please let me know the code to change. Thanks!

     
  • TNTEverett

    TNTEverett - 2010-03-15

    You will need to change the code in processor.php.  No one can tell you exactly what teh changes will be because it will be specific to your form only. 

     
  • John W.

    John W. - 2010-03-15

    Thanks for your reply. If you can give me the typical code, I can modify it to suit my installation. The reason I had for doing this is to have notification e-mails that would take me to browse the database in addition to the form data by e-mail. I have discovered that maybe this Beta release does not send links to SQL. Is this correct? If so, did the previous version have the SQL browse feature? If so, and if it is possible to map the fields and code this into the new version, please let me know typical code for that and I should be able to figure it out.

    Also, I ran across an old thread that discussed code for allowing the form to be submitted in my domain only, but there were problems that caused that not to work. Is there coding that will work for this now? If so, I would like to add that as well.

    Thanks,

    John

     
  • TNTEverett

    TNTEverett - 2010-03-15

    Here is SQL write, email, and file write in one example processor.php file.

    <?php
    $where_form_is="http://".$_SERVER.strrev(strstr(strrev($_SERVER),"/"));

    include("config.inc.php");
    $link = mysql_connect($db_host,$db_user,$db_pass);
    if(!$link) die ('Could not connect to database: '.mysql_error());
    mysql_select_db($db_name,$link);
    $query = "INSERT into `".$db_table."` (field_1,field_2) VALUES ('" . $_POST . "','" . $_POST . "')";
    mysql_query($query);
    mysql_close($link);

    $message="firstname: ".$_POST."
    lastname: ".$_POST."";
    $message = stripslashes($message);
    $email_to="\"youremail@youurl.org\"";

    mail($email_to,"Form Submitted at your website",$message,"From: phpFormGenerator");

    $make=fopen("admin/data.dat","a");
    $to_put="";
    $to_put .= $_POST."|".$_POST."";
    fwrite($make,$to_put);

    include("confirm.html");
    ?>

     
  • John W.

    John W. - 2010-03-16

    Are there specific files from the previous version(s) needed for browsing the data? Can the existing lines that mail the form data be left where they are so both e-mail messages can be sent?

    Thanks for your help. The only problem I had with generating the form was several mismatched feilds. I believe it was caused from moving two fields higher in the list. The fields moved up in form.html but were left in the previous positions in processor.php. I just had to edit the php to move the labels to their matching field numbers. I was unable to find any documentation, but it was easy to follow. I added FROM and REPLY-TO headers to pick up the senders address.

    Nice application!

     
  • TNTEverett

    TNTEverett - 2010-03-16

    The previous version admin folder can be ported to the new version in order to browse the db you create.  There may be some minor tweaks required.  I have done this successfully so I know it is possible. 

     
  • John W.

    John W. - 2010-03-16

    I'm having a problem with one part of the code. Can you verify the correct code highlighted in red and let me know what the function of that part is? Thanks.

    <?php
    $where_form_is="http://".$_SERVER.strrev(strstr(strrev($_SERVER),"/")); include("config.inc.php"); $link = mysql_connect($db_host,$db_user,$db_pass); if(!$link) die ('Could not connect to database: '.mysql_error()); mysql_select_db($db_name,$link); $query = "INSERT into `".$db_table."` (field_1,field_2) VALUES ('" . $_POST . "','" . $_POST . "')"; mysql_query($query); mysql_close($link); $message="firstname: ".$_POST." lastname: ".$_POST.""; $message = stripslashes($message); $email_to="\"youremail@youurl.org\""; mail($email_to,"Form Submitted at your website",$message,"From: phpFormGenerator"); $make=fopen("admin/data.dat","a"); $to_put=""; $to_put .= $_POST."|".$_POST.""; fwrite($make,$to_put); include("confirm.html"); ?>

     
  • John W.

    John W. - 2010-03-16

    The BBCode color tag didn't seem to work. This is the part I need help with:

    $to_put .= $_POST."|".$_POST."";

     
  • TNTEverett

    TNTEverett - 2010-04-14

    The "$to_put" variable is used to store values written to a file based db.  In your example it is preparing to write the same form variable into the admin/data.dat file twice. 

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.