QWERTYtech Posted May 22, 2007 Share Posted May 22, 2007 Okay, I have created my Contact.php now and I have my Mailer.php file to do the mailing. I have a few questions about my Mailer.php now. <?php if(isset($_POST['submit'])) { $to = "admin@qwertytech.bounceme.net"; $subject = $_POST['EmailSubject']; $name_field = $_POST['SenderName']; $email_field = $_POST['SenderEmail']; $message = $_POST['ContactMessage']; $ip = @$REMOTE_ADDR; $datetime = date('l dS \of F Y h:i:s A'); $body = "From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message"; echo "Data has been submitted to site Administrator!"; mail($to, $subject, $body); } else { echo "Please try again!"; } ?> I was wanting to know if the $ip and $datetime is coded right.... Also, what code would I have to add to put a copy of this Contact form to a database???? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 22, 2007 Share Posted May 22, 2007 Your $ip should be: $ip = $_SERVER['REMOTE_ADDR']; Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted May 22, 2007 Share Posted May 22, 2007 Regarding your question about saving a record in a database, I would suggest that you find a PHP-MySQL tutorial / guide and learn how to created database tables, connect to the database, insert data, receive data ect.. of course only if you do not already know If someone posted the complete code to create the db table, connect and post data it would confuse you if you don't have any basic experience with databases Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted May 22, 2007 Share Posted May 22, 2007 http://www.phpfreaks.com/tutorials/142/0.php Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 22, 2007 Author Share Posted May 22, 2007 Okay, so i have read the article that you reconmended.... that was very helpful. Thank you! The only thing I have a question is, in the $sql command how do i insert multiple value into multiple fields? <?php if(isset($_POST['submit'])) { // database information $host = 'localhost'; $user = 'admin'; $password = 'password'; $dbName = 'QWERTYTECH'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // Information for EMAIL $to = "admin@qwertytech.bounceme.net"; $subject = $_POST['EmailSubject']; $name_field = $_POST['SenderName']; $email_field = $_POST['SenderEmail']; $message = $_POST['ContactMessage']; $ip = $_SERVER['REMOTE_ADDR']; $datetime = date('l dS \of F Y h:i:s A'); $body = "From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message"; echo "Data has been submitted to site Administrator!"; mail($to, $subject, $body); // insert new entry into database $sql = "insert into Contact (someField) values ('$newEntry')"; $result = mysql_query($sql, $conn) or die(mysql_error()); } else { echo "Please try again!"; } ?> Are there suppost to be () around the $sql data? Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 22, 2007 Share Posted May 22, 2007 Replace with your values. $sql = "insert into Contact (someField, someField2, someField3) values ('$newEntry', '$newEntry2', '$newEntry3')"; Get the pattern? Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 26, 2007 Author Share Posted May 26, 2007 Okay, so i have created the following mailer.php page.... <?php if(isset($_POST['submit'])) { // database information $host = 'localhost'; $user = 'admin'; $password = 'password'; $dbName = 'newdb'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // Information for EMAIL $to = "admin@mydomain.com"; $subject = $_POST['EmailSubject']; $name_field = $_POST['SenderName']; $email_field = $_POST['SenderEmail']; $message = $_POST['ContactMessage']; $ip = $_SERVER['REMOTE_ADDR']; $datetime = date('l dS \of F Y h:i:s A'); $body = 'From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message'; // insert new entry into database $sql = 'insert into Contact (Contact_Name, Contact_Email, Contact_Date, Contact_IP, Contact_Subject, Contact_Message)values ('$name_field', '$email_field', '$datetime', '$ip', '$subject', '$message')'; $result = mysql_query($sql, $conn) or die(mysql_error()); echo 'Data has been submitted to site Administrator!'; mail($to, $subject, $body); } else { echo "Please try again!"; } ?> Whenever I submit the following mailer.php i get no emails..... What am I doing wrong? I don't even get the 'Data has been submitted to site Administrator' or 'Please try again!'. Please someone help me. Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 Does your form use the method "post"? Is your submit button named 'submit'? Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 26, 2007 Author Share Posted May 26, 2007 yes & yes Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 For test purposes, replace: <?php if(isset($_POST['submit'])) { with: <?php if(isset($_POST['submit'])) { echo "hello"; Does it echo hello? Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 27, 2007 Author Share Posted May 27, 2007 No, it just displays a blank screen. what could I be doing wrong? Is there a way for it to echo a message back to a "clean" contact.html page? Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 contact.html - no php code is executed on the server in an html file ... unless you have configured things to parse .html files as if they were .php files. Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 27, 2007 Author Share Posted May 27, 2007 im confused. I have an html file called contact.html that has my form in it. The form has an method of POST and action of contact.php. The contact.php has the code that i have posted above. Have i created my contact me wrong? Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 contact.php is OK. If that refuses to do anything like execute the code inside your if (isset conditional then the isset condition can't be true. Can we see the html form and the contact.php script in full? Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 Contact.html <form name="phpformmailer" action="mailer.php" align="center" method="post"> <div align="center"> <center> <table bgcolor="#F2F2F2" width="528" cellspacing="6"> <tr> <td width="159"><strong>Contact Us</strong></td> <td width="349"><a href="index.html">Home</a> > <a href="contact.html">Conctact Us</a></td> </tr> <tr> <td align="right" width="159"><small>Your name:</small></td> <td width="349"><font face="Arial"><input class="inputc" size="29" name="name"></font></td> </tr> <tr> <td align="right" width="159"><font color="red" size="1">*</font><small> Your email address:</small></td> <td align="left" width="349"><font face="Arial"><input class="inputc" size="29" name="email"></font></td> </tr> <tr align="middle"> <td align="right" width="159"><font color="red" size="1">*</font><small> Confirm email address:</small></td> <td width="349" align="left"><font face="Arial"><input class="inputc" size="29" name="email2"></font></td> </tr> <tr> <td align="right" width="159"><font color="red" size="1">*</font><small> Subject:</small></td> <td width="349"><font face="Arial"><input class="inputc" size="29" name="thesubject"></font></td> </tr> <tr> <td align="right" width="159"> <p><font color="#000080" size="1">*</font><small> Your request or query:</small></td> <td width="349"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="27"></textarea></td> </tr> <tr> <td width="159"></td> <td width="349"> <script language="JavaScript"><!-- function validateForm() { var okSoFar=true with (document.phpformmailer) { var foundAt = email.value.indexOf("@",0) if (foundAt < 1 && okSoFar) { okSoFar = false alert ("Please enter a valid email address.") email.focus() } var e1 = email.value var e2 = email2.value if (!(e1==e2) && okSoFar) { okSoFar = false alert ("Email addresses you entered do not match. Please re-enter.") email.focus() } if (thesubject.value=="" && okSoFar) { okSoFar=false alert("Please enter the subject.") thesubject.focus() } if (themessage.value=="" && okSoFar) { okSoFar=false alert("Please enter the details for your enquiry.") themessage.focus() } if (okSoFar==true) submit(); } } // --></script> <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> <small><small> You must fill in the fields marked with a <font color="red">*</font></small></small> </td> </tr> </table> </center></div> </form> mailer.php <?php if(isset($_POST['submit'])) { echo 'hello world'; // database information $host = 'localhost'; $user = 'testdb'; $password = 'password'; $dbName = 'testdb'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // Information for EMAIL $to = "admin@mydomain.net"; $subject = $_POST['EmailSubject']; $name_field = $_POST['SenderName']; $email_field = $_POST['SenderEmail']; $message = $_POST['ContactMessage']; $ip = $_SERVER['REMOTE_ADDR']; $datetime = date('l dS \of F Y h:i:s A'); $body = 'From: $name_field\n E-Mail: $email_field\n Date/Time: $datetune\n IP Address: $ip\n\n Message:\n $message'; // insert new entry into database $sql = 'insert into Contact (Contact_Name, Contact_Email, Contact_Date, Contact_IP, Contact_Subject, Contact_Message) values ('$name_field', '$email_field', '$datetime', '$ip', '$subject', '$message')'; $result = mysql_query($sql, $conn) or die(mysql_error()); echo 'Data has been submitted to site Administrator!'; mail($to, $subject, $body); } else { echo "Please try again!"; } ?> The DB connect is so that i can save a copy of the contact info in a db. If this is messign it up, I will take it out. I thank you for your help. Is there a mor efficient way to do this than I am doing? Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 Since there is no form input named submit, checking to see if $submit is set in the $_POST array will always fail. I suppose you can always add a hidden input named submit with some non-null value (it will exist, therefore, and your present js submit can be used). Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 Well I changed to button to Submit type and tried it. I did not get anything in my mail.... hmmmm.... any other ideas? Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 First question: after you changed the submit type did you see the 'hello world' echoed? If not, the code is still failing the isset test. If it passed that test, did anything get added to the database? There are many reasons why you might not have received the email, but let's make sure the code is executing before we look into those. Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 Nothing was stored in the DB and no the "hello world" did not show up. Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 Then clearly the isset test is failing - do you actually have an input that is named 'submit' (not B1!)? Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 It was named B1 but I changed it to submit but nothing happened again. Quote Link to comment Share on other sites More sharing options...
eZe616 Posted May 28, 2007 Share Posted May 28, 2007 doubt it'll help , but try changing the type=buton => type=submit ??? :-\ Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 already have done that... nothing... this is what the submit btn code looks like now.... <input type="submit" value="Submit" name="Submit" ONCLICK="javascript:validateForm()"> Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 If the name of the submit button is Submit, then you need to check to see if $_POST['Submit'] is set. submit is NOT the same as Submit. Quote Link to comment Share on other sites More sharing options...
QWERTYtech Posted May 28, 2007 Author Share Posted May 28, 2007 they are both 'S' . Still nothing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.