Van.G Posted June 5, 2009 Share Posted June 5, 2009 Hi, I have to start by saying my php skills are very limited and I am really new to this whole thing. I have a php form setup and it does work. I am just not happy with how it currently functions and want the following things to happen. I think this should be pretty straight forward. 1. I want this page to send the mail and not reload a new page. The reason for this is that currently it clears all entered data if the verification code is incorrect. 2. I don't want a $msg for the thank you. I would prefer it to redirect to a new target page. That way the form can be removed and it would only contain a thank message. 3. Is there a way to make sure these messages do not get flagged as spam or junk mail. It seems to differ from client to client. Here's my current code: <? session_start(); if(isset($_POST['captcha']) and $_POST['captcha']!="" and md5($_POST['captcha'])==$_SESSION['IHCvalue']) { // Email Submit $message .= '<br>Following details has been submitted<br><br>'; $message .= '<br>First Name: '.$_POST['firstname']; $message .= '<br>Last Name: '.$_POST['lastname']; $message .= '<br>Organization: '.$_POST['organization']; $message .= '<br>Email: '.$_POST['email']; $message .= '<br>Affiliation: '.$_POST['affiliation']; $message .= '<br>Phone: '.$_POST['phone']; $message .= '<br>Street Address: '.$_POST['street']; $message .= '<br>City: '.$_POST['city']; $message .= '<br>State: '.$_POST['usstate']; $message .= '<br>Zip: '.$_POST['zip']; $from = "Van Gould <[email protected]>"; ini_set("sendmail_from", $from); $subject = "Building Prop X Newsletter Sign Up"; $to = "[email protected]"; mail($to, $subject,$message,"From: $from\nContent-Type: text/html; charset=iso-8859-1"); // autoresponse $subject = "Form Confirmation"; $message="Thank you!"; $to = trim($_POST['email']); mail($to, $subject,$message,"From: $from\nContent-Type: text/html; charset=iso-8859-1"); $msg = "Thank you for signing up for our newsletter!"; } else { $msg = "Invalid Verification 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>Sign Up Form</title> <link rel="stylesheet" type="text/css" href="css/propmain.css" /> <script type="text/javascript"> <!-- function validateAndSend() { if (document.getElementById("firstname").value == "") { alert("Please provide your first name!"); return false; } if (document.getElementById("lastname").value == "") { alert("Please provide your last name!"); return false; } if (document.getElementById("organization").value == "") { alert("Please provide your organization!"); return false; } if (document.getElementById("email").value == "") { alert("Please provide email!"); return false; } else { if (document.getElementById("email").value.indexOf("@") == -1) { alert("Please provide a valid email address!"); return false; } } if (document.getElementById("affiliation").value == "") { alert("Please provide your SBUSD Affiliation!"); return false; } if (document.getElementById("phone").value == "") { alert("Please provide your phone number!"); return false; } if (document.getElementById("street").value == "") { alert("Please provide your street address!"); return false; } if (document.getElementById("city").value == "") { alert("Please provide your city!"); return false; } if (document.getElementById("usstate").value == "") { alert("Please provide your state!"); return false; } if (document.getElementById("zip").value == "") { alert("Please provide your zip!"); return false; } if (document.getElementById("captcha").value == "") { alert("Please provide image verification code!"); return false; } return true; } //--> </script> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> <body> <form name="myform" id="myform" method="post" class="form" action="newslettersignup.php" enctype="multipart/form-data"> <table width="460" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" class="requiredprompt"><span class="homephone"><?=$msg?></span><br /><span class="required">*</span>indicates a required field</td> </tr> <tr> <td width="60" class="formcopy"> First Name<span class="required">*</span></td> <td width="101" class="formitems"><input name="firstname" type="text" class="input" id="firstname" maxlength="50" /></td> </tr> <tr> <td class="formcopy">Last Name<span class="required">*</span></td> <td class="formitems"><input name="lastname" type="text" class="input" id="lastname" maxlength="50" /></td> </tr> <tr> <td class="formcopy">Organization<span class="required">*</span></td> <td class="formitems"><input name="organization" type="text" class="input" id="organization" maxlength="50" /></td> </tr> <tr> <td class="formcopy"> Email<span class="required">*</span></td> <td class="formitems"><input name="email" type="text" class="input" maxlength="50" id="email" /></td> </tr> <tr> <td class="formcopy">SBUSD Affiliation<span class="required">*</span></td> <td class="formitems"><input name="affiliation" type="text" class="input" maxlength="50" id="affiliation" /></td> </tr> <tr> <td class="formcopy">Phone<span class="required">*</span></td> <td class="formitems"><input name="phone" type="text" class="input" maxlength="50" id="phone" /></td> </tr> <tr> <td class="formcopy">Street Address<span class="required">*</span></td> <td class="formitems"><input name="street" type="text" class="input" maxlength="50" id="street" /></td> </tr> <tr> <td colspan="2"><table width="460" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="formcopystate">City<span class="required">*</span></td> <td class="formitemsm"> <input name="city" type="text" class="input_city" maxlength="50" id="city" /></td> <td class="formcopystate">State<span class="required">*</span></td> <td class="formitemsm"><select name="usstate" class="input_state" id="usstate"> <option value="" selected="selected">-----</option> <option value="AL">AL </option> <option value="AK">AK </option> <option value="AZ">AZ </option> <option value="AR">AR </option> <option value="CA">CA </option> <option value="CO">CO </option> <option value="CT">CT </option> <option value="DE">DE </option> <option value="DC">DC </option> <option value="FL">FL </option> <option value="GA">GA </option> <option value="HI">HI </option> <option value="ID">ID </option> <option value="IL">IL </option> <option value="IN">IN </option> <option value="IA">IA </option> <option value="KS">KS </option> <option value="KY">KY </option> <option value="LA">LA </option> <option value="ME">ME </option> <option value="MD">MD </option> <option value="MA">MA </option> <option value="MI">MI </option> <option value="MN">MN </option> <option value="MS">MS </option> <option value="MO">MO </option> <option value="MT">MT </option> <option value="NE">NE </option> <option value="NV">NV </option> <option value="NH">NH </option> <option value="NJ">NJ </option> <option value="NM">NM </option> <option value="NY">NY </option> <option value="NC">NC </option> <option value="ND">ND </option> <option value="OH">OH </option> <option value="OK">OK </option> <option value="OR">OR </option> <option value="PA">PA </option> <option value="RI">RI </option> <option value="SC">SC </option> <option value="SD">SD </option> <option value="TN">TN </option> <option value="TX">TX </option> <option value="UT">UT </option> <option value="VT">VT </option> <option value="VA">VA </option> <option value="WA">WA </option> <option value="WV">WV </option> <option value="WI">WI </option> <option value="WY">WY</option> </select></td> <td class="formcopystate">Zip<span class="required">*</span></td> <td class="formitemsm"> <input name="zip" type="text" class="input_city" maxlength="50" id="zip" /></td> </tr> </table></td> </tr> <tr> <td valign="top" class="formcopy">Verification Image:</td> <td valign="top" class="formitems"><img src="captcha.php" id="captcha_img" style="float:left;"><br /> <div style="float:right; width:150px;" class="captachregen"> Cannot read the image? <a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src='captcha.php?'+Math.random();">Click Here</a> to generate a new one.</div></td> </tr> <tr> <td valign="top" class="formcopy">Type the Numbers from the Image Above:</td> <td valign="top" class="formitems"><input type="text" name="captcha" id="captcha" class="input"></td> </tr> <tr> <td valign="top" class="formcopy"> </td> <td class="formitems"><div align="right"> <input type="submit" name="Submit" value="Submit" onclick="return validateAndSend()" /> </div></td> </tr> </table> </form> </body> </html> Thanks in advance for any insight! Van Link to comment https://forums.phpfreaks.com/topic/161094-php-mail-to-form-with-captcha/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.