brandond Posted May 5, 2009 Share Posted May 5, 2009 I found the code from two seperate mailer forms that I liked, and tried to modify them together to get what I needed. However, when I click the submit button, nothing happens and i'm unsure why. I just started working w/ php in the last month or so, and not 100% sure how to go about debugging everything properly yet. here is the code that i'm using This is contact.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="default3.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #000000; } td img { display: block; } body { background-color: #000000; } .style1 { color: #000000 } body,td,th { color: #000000; font-family: Geneva, Arial, Helvetica, sans-serif; } .style2 { font-size: 16px } .style3 { color: #000000; font-size: 16px; } </style> <script type="text/JavaScript"> <!-- function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> </head> <body onload="MM_preloadImages('images/nav_r1_c3_f2.gif','images/nav_r1_c5_f2.gif','images/nav_r2_c1_f2.gif')"> <div id="header"> <div id="menu"> </div> <div> <p> </p> <table width="445" border="0" align="center" cellpadding="0" cellspacing="0"> <!-- fwtable fwsrc="Untitled" fwbase="nav.gif" fwstyle="Dreamweaver" fwdocid = "849900832" fwnested="0" --> <tr> <td><img src="images/spacer.gif" width="49" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="95" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="90" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="97" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="114" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td colspan="2"><img src="images/nav_r1_c1.gif" width="144" height="1" border="0" id="nav_r1_c1" alt="" /></td> <td rowspan="2"><a href="services.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('nav_r1_c3','','images/nav_r1_c3_f2.gif',1);"><img src="images/nav_r1_c3.gif" width="90" height="17" border="0" id="nav_r1_c3" alt="" /></a></td> <td rowspan="3"><img src="images/nav_r1_c4.gif" width="97" height="18" border="0" id="nav_r1_c4" alt="" /></td> <td rowspan="2"><a href="contact.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('nav_r1_c5','','images/nav_r1_c5_f2.gif',1);"><img src="images/nav_r1_c5.gif" width="114" height="17" border="0" id="nav_r1_c5" alt="" /></a></td> <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td rowspan="2"><a href="index.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('nav_r2_c1','','images/nav_r2_c1_f2.gif',1);"><img src="images/nav_r2_c1.gif" width="49" height="17" border="0" id="nav_r2_c1" alt="" /></a></td> <td rowspan="2"><img src="images/nav_r2_c2.gif" width="95" height="17" border="0" id="nav_r2_c2" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="16" border="0" alt="" /></td> </tr> <tr> <td><img src="images/nav_r3_c3.gif" width="90" height="1" border="0" id="nav_r3_c3" alt="" /></td> <td><img src="images/nav_r3_c5.gif" width="114" height="1" border="0" id="nav_r3_c5" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <br /> </table> <div id="content"> <div style="margin-left: auto;margin-right: auto;"> <center> <form name="phpmailer" action="mailer.php" align="center" method="post"> <table width="570" cellspacing="6"> <tr> <td align="right" width="66"> </td> <td align="right" width="66"><small>Name:</small></td> <td align="left" width="400"> <font face="Arial"> <input type="text" name="name" size="40"> </font> </td> </tr> <tr> <td align="right" width="66"> </td> <td align="right" width="66"><font color="#000080" size="1">*</font><small> Email:</small></td> <td align="left" width="400"> <font face="Arial"> <input type="text" name="email" size="40"> </font> </td> </tr> <tr align="middle"> <td align="right" width="66"> </td> <td align="right" width="66"><font color="#000080" size="1">*</font><small> Confirm email:</small></td> <td width="400" align="left"><font face="Arial"><input type="text" name="email2" size="40"> </font></td> </tr> <tr> <td align="right" width="66"> </td> <td align="right" width="66"><font color="#000080" size="1">*</font><small> Subject:</small></td> <td width="400"> <label> <select size="1" name="subject"> <option>php</option> <option>xml</option> <option>asp</option> <option>jsp</option> </select> </label> </td> </tr> <tr> <td align="right" width="66"> </td> <td align="right" width="66"> <p><small>Question or<br /> Comments:</small></td> <td width="400"><textarea rows="9" name="message" cols="45"></textarea> </tr> <tr> <td width="66"></td> <td width="66"></td> <td width="400"><p> <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> <small> <strong><small>You must fill in the fields marked with a *</strong></p> </td> </tr> </table> </form> <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) { block_spam_bots.value=4*3;//spam bots currently cant read JavaScript, if could then they'd fail the maths! submit(); } } } // --></script> </center> </div> </div> <div> <img src="images/footer.jpg" alt="" width="740" height="253" /> </div> </div> <br /> <div id="footer"></div> </div> </body> </html> here is mailer.php <?php if(isset($_POST['submit'])) { $to = "[email protected]"; //$replyemail = "email" $subject = $_POST['subject']; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; //$dropdown = $_POST['drop_down']; $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";// $replyemail"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> Link to comment https://forums.phpfreaks.com/topic/156882-having-trouble-with-a-mailer-form/ Share on other sites More sharing options...
Hybride Posted May 5, 2009 Share Posted May 5, 2009 "Nothing happens" as in, it doesn't go to the mailer.php script or it does, but nothing shows up? As far as this JS validation goes, all of it can be done in PHP. Also, change <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> to <input type="submit" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()"> The original one was asking for a generic button, not a specific "submit", so the form couldn't do anything. Link to comment https://forums.phpfreaks.com/topic/156882-having-trouble-with-a-mailer-form/#findComment-826808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.