custom form and email
-
Hello,
I have a built a custom theme for a client. The client wants a custom form which I have designed based off of the pdf document he provided me with. once the form has been filled out it then needs to be sent via email to the clients website I am working on. Where I am having problems is that the email will not be sent then I am sent to a blank page of the theme I created, the page uses a template that I created and the form is hard coded within that. Here is the code I have written up with no luck of a email being sent, I am using my email as a test email<?php /* Template Name: Annual Residential Services Agreement */ if(isset($_POST['submitted'])) { if(trim($_POST['name']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['name']); } if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!preg_match("/^:alnum:[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } if(trim($_POST['street']) === '') { $commentError = 'Please enter a street.'; $hasError = true; } else { if(function_exists('stripslashes')) { $street = stripslashes(trim($_POST['street'])); } else { $street = trim($_POST['comments']); } } if(trim($_POST['city']) === '') { $commentError = 'Please enter a city.'; $hasError = true; } else { if(function_exists('stripslashes')) { $city = stripslashes(trim($_POST['city'])); } else { $city = trim($_POST['city']); } } if(trim($_POST['zip']) === '') { $commentError = 'Please enter a zip code.'; $hasError = true; } else { if(function_exists('stripslashes')) { $zip = stripslashes(trim($_POST['zip'])); } else { $zip = trim($_POST['zip']); } } if(trim($_POST['hphone']) === '') { $commentError = 'Please enter a home phone number.'; $hasError = true; } else { if(function_exists('stripslashes')) { $homephone = stripslashes(trim($_POST['hphone'])); } else { $homephone = trim($_POST['hphone']); } } if(trim($_POST['cphone']) === '') { $commentError = 'Please enter a cell phone number.'; $hasError = true; } else { if(function_exists('stripslashes')) { $cphone = stripslashes(trim($_POST['cphone'])); } else { $cphone = trim($_POST['cphone']); } } if(trim($_POST['sdivision']) === '') { $commentError = 'Please enter a street.'; $hasError = true; } else { if(function_exists('stripslashes')) { $sdivision = stripslashes(trim($_POST['sdivision'])); } else { $sdivision = trim($_POST['sdivision']); } } if(trim($_POST['signature']) === '') { $commentError = 'You must enter your Signature.'; $hasError = true; } else { if(function_exists('stripslashes')) { $signature = stripslashes(trim($_POST['signature'])); } else { $signature = trim($_POST['signature']); } } if(!isset($hasError)) { $emailTo = get_option('admin_email'); if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = get_option('admin_email'); } $subject = "Annual Residential Services Agreement". $client_name .""; $body = " <table width=534 border=1 bordercolor=#333333 cellpadding=0 cellspacing=0> <tr> <td width=215>Client Name:</td> <td width=303>". $client_name ."</td> </tr> <tr> <td>Street:</td> <td>". $street ."</td> </tr> <tr> <td>City:</td> <td>". $city ."</td> </tr> <tr> <td>State:</td> <td>". $state ."</td> </tr> <tr> <td>Zip Code:</td> <td>". $zip ."</td> </tr> <tr> <td>Home Phone:</td> <td>". $home_phone ."</td> </tr> <tr> <td>Cell Phone:</td> <td>". $cell_phone ."</td> </tr> <tr> <td>Email:</td> <td>". $email ."</td> </tr> <tr> <td>Subdivision:</td> <td>". $subdivision ."</td> </tr> <tr> <td>2012 Winterization only:</td> <td>". $option1 ."</td> </tr> <tr> <td>2012 Winterization 2013 Startup:</td> <td>". $option2 ."</td> </tr> <tr> <td>2012 Winterization/2013 Startup & 2013 Chesterfield Backflow Test:</td> <td>". $option3 ."</td> </tr> <tr> <td>Customer Signature:</td> <td>". $signature ."</td> </tr> </table> "; $headers = 'From: '.$client_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?PHP get_header(); ?> <div id="main"> <div id="agreement"> <DIV id="page_1"> <P class="p0 ft0">Annual Residential Services Agreement</P> <TABLE cellpadding=0 cellspacing=0 class="t0"> <TR> <TD class="tr0 td0"><P class="p1 ft1">INDIVIDUAL SERVICE PRICING</P></TD> <TD class="tr0 td1"><P class="p2 ft2"> </P></TD> <TD colspan=2 class="tr0 td2"><P class="p3 ft3"><NOBR>PRE-PAY</NOBR> PACKAGE PRICE</P></TD> </TR> <TR> <TD class="tr1 td0"><P class="p2 ft4">2012 WINTERIZATION</P></TD> <TD class="tr1 td1"><P class="p4 ft4">$59</P></TD> <TD class="tr1 td3"><P class="p5 ft5">2012 WINTERIZATION &</P></TD> <TD class="tr1 td4"><P class="p2 ft2"> </P></TD> </TR> <TR> <TD class="tr2 td0"><P class="p2 ft4">2013 SPRING START UP</P></TD> <TD class="tr2 td1"><P class="p4 ft4">$59</P></TD> <TD class="tr2 td3"><P class="p5 ft6">2013 SPRING START UP</P></TD> <TD class="tr2 td4"><P class="p6 ft6">$99</P></TD> </TR> <TR> <TD class="tr3 td0"><P class="p2 ft4">2013 CHESTERFIELD BACKFLOW TEST</P></TD> <TD class="tr3 td1"><P class="p4 ft7">$49</P></TD> <TD class="tr3 td3"><P class="p5 ft5">WITH CHESTERFIELD</P></TD> <TD class="tr3 td4"><P class="p2 ft2"> </P></TD> </TR> <TR> <TD class="tr4 td0"><P class="p2 ft4">TOTAL COST IF PURCHASED INDIVIDUALLY</P></TD> <TD class="tr4 td1"><P class="p4 ft4">$167</P></TD> <TD class="tr4 td3"><P class="p5 ft6">2013 BACKFLOW TEST</P></TD> <TD class="tr4 td4"><P class="p7 ft6">$129</P></TD> </TR> </TABLE> <form action="<?php the_permalink(); ?>" id="arsa" method="post"> <P class="p8 ft8">When purchasing the <NOBR>pre-pay</NOBR> package, you receive an additional 10% discount on 2013 service calls & repairs.</P> <P class="p9 ft9">CUSTOMER INFORMATION</P> <P class="p10 ft10">Name <input type="text" name="name" size="55"></P> <P class="p10 ft11">Street <input type="text" name="street">City <input type="text" name="city">Zip <input type="text" name="zip"></P> <P class="p11 ft10">Home Phone <input type="text" name="hphone">Cell Phone<input type="text" name="cphone"></P> <P class="p12 ft11">Email Address <input type="email" name="email"> Subdivision Name <input type="text" name="sdivision"></P> <P class="p13 ft10">I desire the following: (please check the appropriate item)</P> <TABLE cellpadding=0 cellspacing=0 class="t1"> <TR> <TD class="tr5 td5"><P class="p14 ft11"><input type="checkbox" name="option1" value="1">2012</P></TD> <TD class="tr5 td6"><P class="p15 ft10">Winterization Only </P></TD> <TD class="tr5 td7"><P class="p16 ft10">$59</P></TD> </TR> <TR> <TD class="tr3 td5"><P class="p14 ft11"><input type="checkbox" name="option2" value="2">2012</P></TD> <TD class="tr3 td6"><P class="p15 ft12">Winterization & 2013 Start Up </P></TD> <TD class="tr3 td7"><P class="p16 ft12">$99</P></TD> </TR> <TR> <TD class="tr4 td5"><P class="p14 ft11"><input type="checkbox" name="option3" value="3">2012</P></TD> <TD class="tr4 td6"><P class="p15 ft11">Winterization/2013 Start Up & 2013 Chesterfield Backflow Test </P></TD> <TD class="tr4 td7"><P class="p16 ft11">$129</P></TD> </TR> </TABLE> <P class="p17 ft10">Please note the following:</P> <P class="p18 ft10"><SPAN class="ft11">1)</SPAN><SPAN class="ft13">Upon submitting this form to Sprinkler Pros, we will contact you for confirmation.</SPAN></P> <P class="p19 ft16"><SPAN class="ft14">2)</SPAN><SPAN class="ft15">Sprinkler Pros will confirm with you the scheduled date of your service. You will also receive an automated telephone call the evening before between 7:30 pm & 8:00 pm as a reminder.</SPAN></P> <P class="p20 ft12"><SPAN class="ft11">3)</SPAN><SPAN class="ft17">For winterizations & start ups, we will need access to the controller. If it is located inside your garage, please make arrangements with our office for access.</SPAN></P> <P class="p21 ft12"><SPAN class="ft14">4)</SPAN><SPAN class="ft17">If your backflow preventer is located outside, please have your system winterized before the first freeze to reduce any chance of damage. All it takes is one night below 30 degrees for damage to occur.</SPAN></P> <P class="p22 ft20"><SPAN class="ft18">5)</SPAN><SPAN class="ft19">When purchasing our package, it is the responsibility of the customer to contact our office for scheduling services. It is not necessary to schedule a backflow test unless it is in a locked area.</SPAN></P> <P class="p23 ft20"><SPAN class="ft21">6)</SPAN><SPAN class="ft19">If there is no access when we arrive for servicing, we will make every effort to contact the customer. If contact cannot be made for access, our office will contact you for rescheduling.</SPAN></P> <P class="p24 ft10"><SPAN class="ft11">7)</SPAN><SPAN class="ft13">Sprinkler Pros will leave at your controller a confirmation that the services have been performed. We will turn your controller to the “off” position when winterizing. If you wish to disconnect it from the receptacle, that is up to the customer.</SPAN></P> <P class="p12 ft10">Customer signature: <input type="text" name="signature" size="75"></P> <P class="p12 ft10">Sign & mail or if sending via web site, type in your name.</P> <input type="submit" value="Submit this Agreement"> | <input type="reset" name="Reset this Agreement"> </form> </DIV> </div> </div> <?PHP get_footer(); ?> </body> </HTML>
I cannot wrap my head around this, I do know that the server uses gmail on a ssl at port 465 I know I have not included this in this version of the code I have provided.. but I have in a previous version of this I wrote.
PREVIOUS CODE
<?PHP // SEND EMAIL TO CLIENTS FROM THE ARSA.PHP PAGE! // DESIGNED BY JOHN GRISSOM // Get the variables needed to pass to the email $client_name = $_GET['name']; $street = $_GET['street']; $city = $_GET['city']; $state = $_GET['state']; $zip = $_GET['zip']; $home_phone = $_GET['hphone']; $cell_phone = $_GET['cphone']; $cemail = $_GET['email']; $subdivision = $_GET['sdivision']; $option1 = $_GET['option1']; $option2 = $_GET['option2']; $option3 = $_GET['option3']; $sig = $_GET['signature']; // Stripslash and other encryptions so that no one can try and hack any of the fields $client_name = trim(stripslashes(mysql_real_escape_string($client_name))); $street = trim(stripslashes(mysql_real_escape_string($street))); $city = trim(stripslashes(mysql_real_escape_string($city))); $state = trim(stripslashes(mysql_real_escape_string($state))); $zip = trim(stripslashes(mysql_real_escape_string($zip))); $home_phone = trim(stripslashes(mysql_real_escape_string($home_phone))); $cell_phone = trim(stripslashes(mysql_real_escape_string($cell_phone))); $cemail = stripslashes(mysql_real_escape_string($cemail)); $subdivision = trim(stripslashes(mysql_real_escape_string($subdivision))); $signature = trim(stripslashes(mysql_real_escape_string($signature))); // SENDS EMAIL USING GOOGLES SMTP SERVER $site_owners_email = '[email protected]'; $site_owners_name = 'John Grissom'; if (strlen($client_name) < 2) { $error['name'] = "Please enter your name"; } if (strlen($street) < 2) { $error['street'] = "Please enter your street"; } if (strlen($city) < 2) { $error['state'] = "Please enter your state"; } if (strlen($zip) < 2) { $error['zip'] = "Please enter your zip code"; } if (strlen($home_phone) < 2) { $error['home_phone'] = "Please enter your home phone number"; } if (strlen($cell_phone) < 2) { $error['cell_phone'] = "Please enter your cell phone number"; } if (strlen($signature) < 2) { $error['signature'] = "Enter your Full name as the Signature Please."; } if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) { $error['email'] = "Please enter a valid email address"; } if (!$error) { require_once('phpmailer/class.phpmailer.php'); $mail = new PHPMailer(); $mail->From = $cemail; $mail->FromName = $client_name; $mail->Subject = "Annual Residential Services Agreement". $client_name .""; $mail->AddAddress($site_owners_email, $site_owners_name); $mail->AddAddress('[email protected]', 'John Grissom'); $mail->Body = $comments; // GMAIL STUFF $mail->Mailer = "smtp"; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->SMTPSecure = "ssl"; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "[email protected]"; // SMTP username $mail->Password = "!!people@theyard"; // SMTP password $mail->Send(); echo "<li class='success'> Congratulations, " . $client_name . ". We've received your email. We'll be in touch as soon as we possibly can! </li>"; } # end if no error else { $response = (isset($error['name'])) ? "<li>" . $error['name'] . "</li> \n" : null; $response .= (isset($error['email'])) ? "<li>" . $error['email'] . "</li> \n" : null; echo $response; } # end if there was an error sending ?>
- The topic ‘custom form and email’ is closed to new replies.