siric009 Posted September 10, 2013 Share Posted September 10, 2013 Anyone please help, i'm very desperate. I am new in php coding, therefore I am having a tough time troubleshooting my website. I have a form on this wedding website to should send the data directly to an email account. It was working perfectly, but all of a sudden as become flakey. Sometimes it will send no problem and other times it will not (not browser specific or device specific). It still appears to work properly once the form is completed. It just never reaches the email. My hosting does allow email to be sent and supports php, I double checked. Thanks in advance to anyone who can help! Again, I am just a begginer with php so it might be something real elementary that i'm doing. ------- This is from my index page: <div id="contact-form" class="clearfix"> <div id="contact" class="section"> <form id="contact-us" action="rsvp-form-send.php" method="post"> <?php if(isset($emailSent) && $emailSent == true) { ?> <p class="info">Thanks for sending us your RSVP! Cant wait to CELEBRATE!</p> <?php } else { ?> <?php if(isset($hasError) || isset($captchaError) ) { ?> <p class="alert">Error submitting the form</p> <?php } ?> <div class="left-container"> <div id="contact-name-container" class="formblock"> <?php if($contactName != '') { ?> <br /><span id="contact-name-error" class="error"><?php echo $contactNameError;?></span> <?php } ?> <label class="screen-reader-text">Name</label> <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" placeholder="your name" /> </div> <div id="rsvp-text-container" class="formblock"> <?php if($rsvpError != '') { ?> <br /><span class="error"><?php echo $rsvpError;?></span> <?php } ?> <label id="rsvp-text" class="screen-reader-text">RSVP total</label> <input type="text" name="rsvpTotal" id="rsvpTotal" value="<?php if(isset($_POST['rsvpTotal'])) echo $_POST['rsvpTotal'];?>" class="txt requiredField" placeholder="#" /> </div> <div id="additional-guest" class="formblock"> <label class="screen-reader-text">Additional guest name(s) <small>(leave blank if your rolling solo!)</small></label> <div class="clearfix"></div> <input type="text" name="guestName1" id="guestName1" value="<?php if(isset($_POST['guestName1'])) echo $_POST['guestName1'];?>" placeholder="guest name 1" /> <input type="text" name="guestName2" id="guestName2" value="<?php if(isset($_POST['guestName2'])) echo $_POST['guestName2'];?>" placeholder="guest name 2" /> <input type="text" name="guestName3" id="guestName3" value="<?php if(isset($_POST['guestName3'])) echo $_POST['guestName3'];?>" placeholder="guest name 3" /> <input type="text" name="guestName4" id="guestName4" value="<?php if(isset($_POST['guestName4'])) echo $_POST['guestName4'];?>" placeholder="guest name 4" /> <input type="text" name="guestName5" id="guestName5" value="<?php if(isset($_POST['guestName5'])) echo $_POST['guestName5'];?>" placeholder="guest name 5" /> <input type="text" name="guestName6" id="guestName6" value="<?php if(isset($_POST['guestName6'])) echo $_POST['guestName6'];?>" placeholder="guest name 6" /> </div> <div class="formblock"> <label class="screen-reader-text">Comments, Questions, Special Requests!</label> <textarea name="comments" id="commentsText" class="txtarea" placeholder="enter your thoughts!"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea> </div> </div> <div class="right-container"> <div id="email-container" class="formblock"> <?php if($emailError != '') { ?> <br /><span class="error"><?php echo $emailError;?></span> <?php } ?> <label class="screen-reader-text">Email Address</label> <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="txt requiredField email" placeholder="email address" /> </div> <p>Total your number of meal choices <br />for yourself and your guest(s)</p> <div class="formblock formblock-no-margin"> <div class="beef-img"></div> <label class="screen-reader-text" id="beef-text">Beef total</label> <input type="text" name="beefTotal" id="beefTotal" value="<?php if(isset($_POST['beefTotal'])) echo $_POST['beefTotal'];?>" class="txt" placeholder="#" /> </div> <div class="formblock formblock-no-margin"> <div class="chicken-img"></div> <label class="screen-reader-text" id="chicken-text">Chicken total</label> <input type="text" name="chickenTotal" id="chickenTotal" value="<?php if(isset($_POST['chickenTotal'])) echo $_POST['chickenTotal'];?>" class="txt" placeholder="#" /> </div> <div class="formblock formblock-no-margin"> <div class="fish-img"></div> <label class="screen-reader-text" id="fish-text">Fish total</label> <input type="text" name="fishTotal" id="fishTotal" value="<?php if(isset($_POST['fishTotal'])) echo $_POST['fishTotal'];?>" class="txt" placeholder="#" /> </div> <div class="formblock"> <label class="screen-reader-text" id="hotel-label">Spending the night in our hotel?</label> <label class="screen-reader-text" id="radio-yes-label">yes</label> <input id='radio-yes' type="radio" value="YES"name="hotel"> <label class="screen-reader-text" id="radio-no-label">no</label> <input id='radio-no' type="radio" value="NO" name="hotel"> </div> <div class="formblock"> <label class="screen-reader-text">Like to dance?</label> <input type="text" name="songRequest" id="songRequest" value="<?php if(isset($_POST['songRequest'])) echo $_POST['songRequest'];?>" class="txt" placeholder="give us a song request" /> </div> <button id="submit-button" name="submit" type="submit" class="subbutton">CLICK TO SEND YOUR RSVP!</button> <input type="hidden" name="submitted" id="submitted" value="true" /> </div> </div> <?php } ?> <div class="clearfix"></div> <!-- End #contact --> </div> </form> </div> -------------------------- This is the scripting on the index page: <!--//--><![CDATA[//><!-- $(document).ready(function() { document.getElementById("contact-us").reset(); $('form#contact-us').submit(function() { $('form#contact-us .error').remove(); var hasError = false; $('.requiredField').each(function() { if($.trim($(this).val()) == '') { var labelText = $(this).prev('label').text(); $(this).parent().append('<span class="error">you forgot your '+labelText+'!</span>'); $(this).addClass('inputError'); /* $("#contactName").onclick().hide("span .error");*/ hasError = true; } else if($(this).hasClass('email')) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if(!emailReg.test($.trim($(this).val()))) { var labelText = $(this).prev('label').text(); $(this).parent().append('<span class="error">oops! you\'ve entered an invalid '+labelText+'.</span>'); $(this).addClass('inputError'); hasError = true; } } }); $('#contactName').click(function(){ if($(this).hasClass('inputError')) { $('#contact-name-container .error').css({ 'display' : 'none' }); } }); $('#rsvpTotal').click(function(){ if($(this).hasClass('inputError')) { $('#rsvp-text-container .error').css({ 'display' : 'none' }); } }); $('#email').click(function(){ if($(this).hasClass('inputError')) { $('#email-container .error').css({ 'display' : 'none' }); } }); if(!hasError) { var formInput = $(this).serialize(); $.post($(this).attr('action'),formInput, function(data){ $('form#contact-us').slideUp("fast", function() { $(this).before('<p class="rsvp-thanks"><strong>Thanks for the RSVP!</strong> <br />Cant wait to CELEBRATE!</p>'); }); }); } return false; }); }); //-->!]]> ------------------------ and this is the backend php file: <?php error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP //If the form is submitted if(isset($_POST['submitted'])) { // require a name from user if(trim($_POST['contactName']) === '') { $contactNameError = 'Forgot your name!'; $hasError = true; } else { $contactName = trim($_POST['contactName']); } // require a RSVP Number if(trim($_POST['rsvpTotal']) === '') { $rsvpError = 'Forgot your RSVP total number!'; $hasError = true; } else { $rsvpTotal = trim($_POST['rsvpTotal']); } // Not required $hotel = trim($_POST['hotel']); $guestName1 = trim($_POST['guestName1']); $guestName2 = trim($_POST['guestName2']); $guestName3 = trim($_POST['guestName3']); $guestName4 = trim($_POST['guestName4']); $guestName5 = trim($_POST['guestName5']); $guestName6 = trim($_POST['guestName6']); $beefTotal = trim($_POST['beefTotal']); $chickenTotal = trim($_POST['chickenTotal']); $fishTotal = trim($_POST['fishTotal']); $songRequest = trim($_POST['songRequest']); // need valid email if(trim($_POST['email']) === '') { $emailError = 'Forgot to enter in your e-mail 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']); } // we need at least some content if(trim($_POST['comments']) === '') { $commentError = 'You forgot to enter a message!'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } // upon no failure errors let's email now! if(!isset($hasError)) { $emailTo = 'nsiri335@live.com'; $subject = ' Wedding RSVP!'; $sendCopy = trim($_POST['sendCopy']); $body = "Name: $contactName \n\nRSVP #: $rsvpTotal \n\nChicken Total #: $chickenTotal \n\nBeef Total #: $beefTotal \n\nFish Total #: $fishTotal \n\nGuest Name 1: $guestName1 \n\nGuest Name 2: $guestName2 \n\nGuest Name 3: $guestName3 \n\nGuest Name 4: $guestName4 \n\nGuest Name 5: $guestName5 \n\nGuest Name 6: $guestName6 \n\nEmail: $email \n\nSong Request: $songRequest \n\nHotel Room?: $hotel \n\nComments: $comments"; $headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); // set our boolean completion value to TRUE $emailSent = true; } } ?> Quote Link to comment Share on other sites More sharing options...
gristoi Posted September 10, 2013 Share Posted September 10, 2013 please put your code into code blocks. no one is going to spend there time reading through 200 lines of unformatted code. thanks Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 12, 2013 Share Posted September 12, 2013 Perhaps the message is being flagged as spam. Has the form been found by spammers yet? Another thing to consider is that your website host may have been flagged as a spammer. With the email solution being flaky, have you considered an alternative? You could, for example, save the RSVPs to a text file or database. It may not be as convenient as email, but it's more reliable. Even if you continue using the e-mail solution, I would recommend that you also save the message to a database/file for backup purposes. Side note: PHP provides a filter for email addresses: http://php.net/manual/en/filter.examples.validation.php 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.