PHP - Moved: Contact Form Repeating Error
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=329670.0 Similar TutorialsHello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=359389.0 I tried fixing my contact.html form with my .php action seperated, i couldn't let it work, so now i'm trying to make one with php inside the html.. with some help of good tutorials of course Is there someone who can tell me if my form is looking oke or definitely not? I didn't work the checkboxes out, so i expect some error's from those lines, but i get an error on line 43... And i cant figure it out... Code: [Select] Parse error: syntax error, unexpected T_VARIABLE in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 43 Line 43 is: Code: [Select] 40 $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; 41 $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; 42 $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; 43 $mail_body .= "Onderwerp: " $_POST['sub']. "\n"; 44 $mail_body .= "Bericht: " $_POST['field']. "\n\n"; 45 $mail_body .= "\n\n -- Einde van het contact bericht --"; 46 mail($recipient, $subject, $mail_body, $header); and the file: Code: [Select] <!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>PHP contact</title> </head> <body> <?php ini_set('display_errors', 'On'); $error_msg = ''; error_reporting(E_ALL | E_STRICT) ; if($_SERVER['REQUEST_METHOD']=="POST") { if(strlen($_POST['voorletters']) ==0) { $error_msg ="- Voorletters.<br>"; } if(strlen($_POST['naam']) ==0) { $error_msg ="- Achternaam.<br>"; } if(strlen($_POST['tel']) ==0) { $error_msg ="- Telefoonnummer.<br>"; } if(!preg_match("/^[_a-zA-Z0-9-]+(\.[*@([a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/", $_POST['uwemail'])) { $error_msg .="- E-mailadres.<br>"; } if(strlen($_POST['field']) ==0) { $error_msg .="- Vraag.<br>"; } if(!empty($error_msg)) { //Een van de velden werd niet goed ingevuld echo "<center><b>Het formulier kan niet worden verzonden...<BR> Onderstaande gegevens zijn 'niet', of 'niet correct' ingevuld:</b><br><br>"; echo $error_msg; echo "<br>Probeer het <a href=javascript:history.back(1)>hier</a> opnieuw en vul alstublieft alle velden in.<br><br></center>"; } else { $recipient = "sven_jcvd@hotmail.com"; //Het email adres van de Ontvanger. $subject = $_POST['Formulier ingevuld']; //Onderwerp van de mail. $header = "From: " . $_POST['uwemail'] . "\n"; $mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; $mail_body .= "De volgende persoon vulde het contact formulier in:\n\n"; $mail_body .= "Naam: " . $_POST['voorletters'] . "\n"; $mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n"; $mail_body .= "Onderwerp: " $_POST['sub']. "\n"; $mail_body .= "Bericht: " $_POST['field']. "\n\n"; $mail_body .= "\n\n -- Einde van het contact bericht --"; mail($recipient, $subject, $mail_body, $header); echo "<center><b>Bedankt voor uw reactie.</b><br><br>Wij zullen zo snel mogelijk contact met u opnemen.<br> Met vriendelijke groet,<br> JPS</b><br><br><br>"; echo "Terug naar het <a class=\"main\" href='javascript:history.back(1)'>formulier</a></center>"; } } else { ?> <form action="<? echo $_SERVER ['PHP_SELF']; ?>" method="POST" name="contact"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><br> <table width="441" height="366" border="0" align="center" cellpadding="0" cellspacing="5" bordercolor="#FFFFFF" bgcolor="#000000"> <tr> <td height="2" colspan="3"><div align="center"><font color="#FFFF00" size="2">Contactformulier</font><br /> <br /> </div> <div align="left"></div> <div align="right"><font color="#FFFF00" size="1">(* verplichte velden)</font></div></td> </tr> <tr> <td height="20" rowspan="2"><div align="left"></div></td> <td width="72" height="7"><div align="left"><font color="#FFFF00" size="1">Voorletters *</font></div></td> <td height="-4"> <div align="left"> <input name="voorletters" type="text" size="10" /> </div> <div align="right"></div> <div align="right"></div></td> </tr> <tr> <td height="8"><font color="#FFFF00" size="1">Achternaam *</font></td> <td height="0"><input name="naam" type="text" id="naam" size="30" name:"naam" /></td> </tr> <tr> <td height="0"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td> <td height="0"><div align="left"><font color="#FFFF00" size="1">Adres</font></div></td> <td height="1"> <div align="left"> <input type="text" name="adres" size="30" maxlength="40" /> </div></td> </tr> <tr> <td height="20" rowspan="2"><div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td> <td height="7"><div align="left"><font color="#FFFF00" size="1">Postcode</font></div></td> <td height="-4"> <div align="left"> <input name="postcode" type="text" size="10" maxlength="7" /> </div> <div align="right"></div> <div align="center"></div> <div align="left"></div></td> </tr> <tr> <td height="8"><font color="#FFFF00" size="1"> Plaats</font></td> <td height="0"><input name="plaats" type="text" id="plaats" size="30" maxlength="40" /></td> </tr> <tr> <td height="1"> </td> <td height="1"> <div align="left"><font color="#FFFF00" size="1">Tel *</font></div></td> <td height="1"><input type="text" name="tel" size="30" maxlength="15" /></td> </tr> <tr> <td width="6" rowspan="2" class="Kleiner"> <div align="left"><font size="2"><font color="#FFFF00"></font></font></div></td> <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Email *</font></div></td> <td height="-2"> <div align="left"> <input name="uwemail" type="text" size="40" maxlength="40" /> </div></td> </tr> <tr> <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Onderwerp</font></div></td> <td height="-2"><input name="sub" type="text" size="40" maxlength="40" /></td> </tr> <tr> <td width="6" class="Kleiner"> </td> <td class="Kleiner"><div align="left"><font color="#FFFF00" size="1">Vraag *</font></div></td> <td rowspan="2"> <div align="left"> <textarea name="field" cols="40" rows="2" wrap="virtual"></textarea> </div></td> </tr> <tr> <td height="15" colspan="2" class="Kleiner"><div align="left"></div></td> </tr> <tr> <td valign="top"> <div align="right"></div></td> <td valign="top"><div align="left"><font color="#FFFF00" size="1">Interesses</font></div></td> <td height="95"> <div align="left"> <label> <input type="checkbox" name="interesse" id="interesses1" value="Keukens"/> <font color="#FFFF00" size="2"> <font size="1">Keukens</font></font></label> <font color="#FFFF00" size="1"><br /> <label> <input type="checkbox" name="interesse" id="interesses3" value="Bakamermeubels"/> Badkamermeubels</label> <br /> <label> <input name="interesse" type="checkbox" id="interesses2" value="Kasten" /> Kasten</label> <br /> <label> <input type="checkbox" name="interesse" id="interesses4" value="Kantoor"/> Kantoor</label> <br /> <label> <input type="checkbox" name="interesse" id="interesses5" value="Tafels"/> Tafels</label> </font><br /> </div></td></tr> <tr> <td colspan="2"> </td> <td height="8"><div align="right"> <input type="reset" name="reset" id="reset" value="Herstel" /> <input type="Submit" name="Submit" value="Verzenden" /> </div></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> <tr> <td> </td> </tr> </table> </td> </tr> </table> </form> <?php } ?> </body> </html> Hi Guys I really hope that someone can help me with Php and Html5 problem. So I started creating my first website (using templates as examples), but with the contact form there my real problem. Ive followed few tutorials and checked everything and code looks right, but for some weird reason I cant receive any emails. Im very new to html5 and php and not really going to use it that offen, just this once for my new business website. Whould really appricate it if someone can have a look and give me some pointers on where I went wrong Attached your find the contact.html & php file
Thanks
This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=306808.0 <?php // Email address verification function isEmail($email) { return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)); } if( ! empty($_POST)) { // Enter the email where you want to receive the message $emailTo = 'email@testing.com; $clientName = trim($_POST['name']); $clientEmail = trim($_POST['email']); $subject = trim($_POST['subject']); $message = trim($_POST['message']); $array = array(); $array['nameMessage'] = ''; $array['emailMessage'] = ''; $array['messageMessage'] = ''; if($clientName == '') { $array['nameMessage'] = 'Please enter your name.'; } if(!isEmail($clientEmail)) { $array['emailMessage'] = 'Please insert a valid email address.'; } if($message == '') { $array['messageMessage'] = 'Please enter your message.'; } if($clientName != '' && isEmail($clientEmail) && $message != '') { // Send email $headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail; mail($emailTo, $subject, $message, $headers); } echo json_encode($array); } ?>Hi all! I am new to PHP and am having trouble figuring out what I am doing wrong. The contact form sends the email but once you click submit it says: {"nameMessage":"","emailMessage":"","messageMessage":""} Please see my script, can someone please help! :-( Thank you in advance :-) This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310594.0 I have a simple problem but seem to be hitting a roadblock with fixing it. I am in the process of upgrading a site from PHP 5.6 to 7.0 (eventually to 7.2) I am seeing error notices like PHP Notice: Undefined index: productpage in ….. I know this it because the $_REQUEST can sometimes be empty depending on what data is passed back and when certain pages are loaded $productpage = mysqli_real_escape_string($con, $_REQUEST['productpage']); I also know that I could turn the error notice off or use isset to check $_REQUEST but I would prefer to use the ?? '' option to fix this issue. The problem is that when I add the ?? '' option to the above code the problem resolved itself but then moments later the same error on the same line reappeared in the error logs and I cant understand why. Can someone give me the correct example of where to place ?? '' in the above code so that I can rule out my potentially dodgy code as being the reason the error keeps reappearing.
I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353621.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358012.0 I was able to edit this code from my word press theme.. I wanted to add a social club ID to as a text field, i was able to add the text field but i cannot seem to get the information from that field sent with the email I edited this contact form file on my word press to try and include a Social ID field, i was able to add the content to the form but i'm unable to get the information sent in the email, keeps giving me awkward results. help plz. <?php session_start(); /** * Template Name: Contact Form */ global $theme; get_header(); ?> <div id="main"> <?php $theme->hook('main_before'); ?> <div id="content"> <?php $theme->hook('content_before'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); /** * Find the post formatting for the pages in the post-page.php file */ get_template_part('post', 'page'); endwhile; else : get_template_part('post', 'noresults'); endif; ?> <div class="contact-form"> <?php if ($_POST['contact_form_submit'] ) { if(!$_POST['contact_form_name'] || !$_POST['contact_form_email'] || !$_POST['contact_form_subject'] || !$_POST['contact_form_socialid'] || !$_POST['contact_form_question'] || !$_POST['contact_form_message']) { ?><div class="error"><?php _e('Please fill in all required fields!','themater'); ?></div><?php } elseif(!is_email($_POST['contact_form_email'])) { ?><div class="error"><?php _e('Invalid email!','themater'); ?></div><?php } elseif(($_SESSION['contact_form_number_one'] + $_SESSION['contact_form_number_two']) != $_POST['contact_form_question']) { ?><div class="error"><?php _e('You entered the wrong solution..','themater'); ?></div><?php } else { wp_mail($theme->get_option('contact_form_email'), sprintf( '[%s] ' . esc_html($_POST['contact_form_subject']), get_bloginfo('name') ), esc_html($_POST['contact_form_message']),'From: "'. esc_html($_POST['contact_form_name']) .'" <' . esc_html($_POST['contact_form_email']) . '>'); unset($_POST); ?><div class="message"><?php _e('Thanks for contacting Devils First MC.','themater'); ?></div><?php } if ( isset($_SESSION['contact_form_number_one'] ) ) unset( $_SESSION['contact_form_number_one'] ); if ( isset($_SESSION['contact_form_number_two'] ) ) unset( $_SESSION['contact_form_number_two'] ); } if ( !isset($_SESSION['contact_form_number_one'] ) ) $_SESSION['contact_form_number_one'] = $contact_form_number_one = rand(1, 9); else $contact_form_number_one = $_SESSION['contact_form_number_one']; if ( !isset($_SESSION['contact_form_number_two'] ) ) $_SESSION['contact_form_number_two'] = $contact_form_number_two = rand(1, 9); else $contact_form_number_two = $_SESSION['contact_form_number_two']; ?> <form method="post" action=""> <input type="hidden" name="contact_form_submit" value="true" /> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_name']) { echo 'contact-form-required'; } ?>"><?php _e('Name','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_name" value="<?php if ( isset($_POST['contact_form_name']) ) { echo esc_attr($_POST['contact_form_name']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_socialid']) { echo 'contact-form-required'; } ?>"><?php _e('Social Club ID','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_socialid" value="<?php if ( isset($_POST['contact_form_socialid']) ) { echo esc_attr($_POST['contact_form_socialid']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_email']) { echo 'contact-form-required'; } ?>"><?php _e('Email','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_email" value="<?php if ( isset($_POST['contact_form_email']) ) { echo esc_attr($_POST['contact_form_email']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_question']) { echo 'contact-form-required'; } ?>"><?php echo $contact_form_number_one; ?> + <?php echo $contact_form_number_two; ?> = ?</div> <div class="contact-form-input"><input type="text" name="contact_form_question" value="" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_subject']) { echo 'contact-form-required'; } ?>"><?php _e('Subject','themater'); ?>:</div> <div class="contact-form-input"><input type="text" name="contact_form_subject" value="<?php if ( isset($_POST['contact_form_subject']) ) { echo esc_attr($_POST['contact_form_subject']); } ?>" /></div> <div class="contact-form-label alignleft <?php if($_POST && !$_POST['contact_form_message']) { echo 'contact-form-required'; } ?>"><?php _e('Message','themater'); ?>:</div> <div class="contact-form-input"><textarea name="contact_form_message" ><?php if ( isset($_POST['contact_form_message']) ) { echo esc_textarea($_POST['contact_form_message']); } ?></textarea></div> <div class="contact-form-label alignleft"> </div> <div class="contact-form-input" style="text-align: center;"><input type="submit" value="<?php _e('Submit','themater'); ?>" /></div> </form> </div> <?php $theme->hook('content_after'); ?> </div><!-- #content --> <?php get_sidebars(); ?> <?php $theme->hook('main_after'); ?> </div><!-- #main --> <?php get_footer(); ?> I made a form using http://www.phpform.org/ but I can't for the life of me write some php that successfully collects all the info and emails it to me. Would love to get some help to stop me pulling m hair out over it - it can't be 'that' complicated? I'd just put the form here for now http://trackcover.com/test/ Im having a problem with my form mail on my websites. Now the problem I have only happens with sites that I upload to my hosting accounts with Host gator. The mail will only deliver to the domain email address it wont deliver to gmail or yahoo or any other email address. I tested the script on an old domain with an Irish hosting account and it works perfectly it delivers to gmail and yahoo and my domain email account. Ive been pulling my hair out talking to Hostgator staff all weekend they keep blaming gmail and yahoo and insist the problem is not on there end. Anyway I was wondering is there anything I can add to my PHP script to make sure it delivers to gmail and yahoo or is there anything wrong with my script as hostgator are saying. Maybe there is a security issue or something Im very new to php so i could be missing something simple.
Thanks for the Help
<?php /* Set e-mail recipient */ $myemail = "info@shaneswebdesign.com"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Enter your name"); $subject = check_input($_POST['subject'], "Write a subject"); $email = check_input($_POST['email']); $website = check_input($_POST['website']); $likeit = check_input($_POST['likeit']); $how_find = check_input($_POST['how']); $comments = check_input($_POST['comments'], "Write your comments"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email URL: $website Area of Interest? $how_find Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: http://www.shanesweb...m/thanks.php'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> I have a little problem with my contact form, basically atm I need to paste this code on every page before the HTML tags: Code: [Select] <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'tekdz@tekdz.com'; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> And this is the code for the contact form: Code: [Select] <div id="contact-wrapper"> <?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p><b>Email Successfully Sent!</b></p> <p>Thank you <strong><?php echo $name;?></strong> for getting in contact with us! Your email was successfully sent and we will be in touch with you soon.</p> <?php } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div> <label for="name"><strong>Name:</strong></label> <input type="text" size="50" name="contactname" id="contactname" value="" class="required" /> </div> <div> <label for="email"><strong>Email:</strong></label> <input type="text" size="50" name="email" id="email" value="" class="required email" /> </div> <div> <label for="subject"><strong>Phone Number:</strong></label> <input type="text" size="50" name="subject" id="subject" value="" class="required" /> </div> <div> <label for="message"><strong>Message:</strong></label> <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea> </div> <input type="submit" value="Send Message" name="submit" class="submit" /> </form> </div> My question is would it be possible to have the php code that goes before html tags in its own file? So I don't have to manually paste that onto each page with the contact form? Any help will be appreciated, thanks Hello All, I've successfully figure out how to make a form that connects to My Database, INSERTS the END USERS INFO into my database, and THEN sends a email notification back to the ME that contains the the END USERS INFO. Is there a line of CODE in PHP to use that I can ALSO send the END USERS INFO from the form THEY FILLED OUT with all their details that was sent back to ME in the initial e-mail? Also how do I get the date and time to post in the in my e-mail received with from the END USERS containing the date and time of the form filled out. It shows up in my Database HOWEVER, not in my RECEIVED e-mail. Here is my code below: <pre> Code: [Select] <?php if (isset($_POST['submitted'])) { include('connect2myDB.php'); $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; $sqlinsert = "INSERT INTO travelers (salutation, first_name, last_name, email, zip_code, newsletter, registation_date) VALUES ('$salutation', '$first_name','$last_name','$email','$zip_code','$newsletter', NOW()))"; } ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'mrjap1jobs@gmail.com'; // GATHERING the FORM DATA VARIABLES $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; // THIS DATA DOES NOT SHOW UP IN MY RECEIVED E-MAIL HOWEVER, IT DOES SHOW UP IN MY DATABASE.... HOW DO I FIX THIS? $body = <<<EOD <br /><hr><br /> <strong>Salutation:</strong> $salutation <br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Zip Code:</strong> $zip_code <br /> <strong>Newsletter:</strong> $newsletter <br /> <strong>Registration Date:</strong> $registation_date <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> </pre> thanks mrjap1 MOD EDIT: code tags added. Hey, I have my contact form in my website working fine I'm just asking a simple question because I don't know so much about php and php syntax I have my html file calling this code below when i'm clicking on the submit button Just take a look at the last line when there is the 'echo' script I want it to go to this link, and instead it's just writing the link what is the right command/code that should i use? <? $subject="from ".$_GET['fName']; $headers= "From: ".$_GET['fEmail']."\n"; $headers.='Content-type: text/html; charset=UTF-8' . "\r\n"; mail("mymail@example.com", $subject, " <html> <head> <title> My Title </title> </head> <body> <br> ".$_GET['fName']. " <br> ".$_GET['fPhone']." <br> ".$_GET['fEmail']." <br><br> ".$_GET['pBody']." </body> </html>" , $headers); echo "http://avrikim123.co.cc/sent.html"; ?> Hi everyone, i was trying to create a little script for my blog but cant do that. What i want is this model with dropdown options: http://www.pasidedans.ro/inscrie-te-acum I want to replace my entire cod so i dont want to modify him.. Can you help me to create a contact form like this ? thanks ! Hello All, I need some VERY DETAILED direction from anyone who can tell me how to complete this task. I set up my database "riptide" in Php MyAdmin for the following data to be submitted by user. Also a " form.php " form with the following fields. Salutation: Mr. Mrs. Ms. Miss. Dr. Prof. (radio buttons) input name="salutation" type="radio" value="Mr." checked First Name: (text input field) input name="first_Name" Last Name: (text input field) input name="last_Name" E-mail: (text input field) input name="email" Zip Code: (text input field) input name="zip_code" Would you like to receive our email newsletter? Yes No (radio buttons) input type="radio" name="newsletter" value="yes" id="newsletter_0" checked Okay here is my dilemma... I need to make web form that will do the following: (1) Connects to my database (2) INSERTS the form data filled out from my user into my MySQL database. (3) I need an email that will be sent to both me and the user who filled out the web form (4) A Thank you page "displaying" all the details the user filled out in the web form. (5) Plus all fields are required and need " validation " especially the e-mail address. I made a page called "process_form. php" that will handle all of this once the submit button is clicked. How do I make this happen? Thanks in advance James Hi all, I am currenlty coding up PHP validation for a contact form and as I know barely any PHP i have been following tutorials and copying code. I have a series of checkboxes which emails out the various products that the user wants. It all works now except that it does not re-direct to a thank you page now and outputs this error at the top of the page. Warning: Invalid argument supplied for foreach() in /home2/xxxxxxxx/public_html/client/contact.php on line 17 Below is the code for the PHP and form, any help would be greatly appreciated. Thank you! Code: [Select] <?php if (isset($_POST['submit'])) { $myemail = 'my@email.com';//<-----Put Your email address here. $title = 'Quote'; $name = $_POST['name']; $company = $_POST['company']; $house = $_POST['house']; $street = $_POST['street']; $postcode = $_POST['postcode']; $daynum = $_POST['daynum']; $evenum = $_POST['evenum']; $email = $_POST['email']; $how = $_POST['how']; $information = $_POST['information']; foreach($_POST['product'] as $value) { $product_msg .= " - $value"; } $errors = array(); // set the errors array to empty, by default $fields = array(); // stores the field values $success_message = ""; // import the validation library require("validation.php"); $rules = array(); // stores the validation rules // standard form fields $rules[] = "required,name,Name is required."; $rules[] = "required,house,House number is required."; $rules[] = "required,street,Street is required."; $rules[] = "required,postcode,Post Code is required."; $rules[] = "required,daynum,Daytime Number is required."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } // no errors! redirect the user to the thankyou page (or whatever) else { // here you would either email the form contents to someone or store it in a database. // To redirect to a "thankyou" page, you'd just do this: // header("Location: thanks.php"); $to = $myemail; $email_subject = "Quote: $name"; $email_body = "You have received a new quote from $name. ". " Here are the details:\n \n Name: $name\n \n Company: $company\n \n House: $house\n \n Street: $street\n \n Postcode: $postcode\n \n Daytime Number: $daynum\n \n Evening Number: $evenum\n \n Email: $email\n \n Products: $product_msg\n \n Additional Information: $information\n \n How: $how"; $headers = "From: $title\n"; $headers .= "Reply-To: $email"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: thank-you.html'); } } ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="contact-form" class="cmxform"> <?php // if $errors is not empty, the form must have failed one or more validation // tests. Loop through each and display them on the page for the user if (!empty($errors)) { echo "<div class='phperror'>Please fix the following errors:\n<ul>"; foreach ($errors as $error) echo "<li>$error</li>\n"; echo "</ul></div>"; } if (!empty($message)) { echo "<div class='notify'>$success_message</div>"; } ?> <fieldset> <label for="name">Name:*</label> <label for="name" class="error">Please enter your name.</label> <input class="text" type="text" id="name" name="name" value="<?=$fields['name']?>"/> <label for="company">Company Name:</label> <input class="text" type="text" id="company" name="company"> <label for="house">House Number:*</label> <label for="house" class="error">Please enter your house number.</label> <input class="text" type="text" id="house" name="house" value="<?=$fields['house']?>"> <label for="street">Street Name:*</label> <label for="street" class="error">Please enter your street name.</label> <input class="text" type="text" id="street" name="street" value="<?=$fields['street']?>"> <label for="postcode">Post Code:*</label> <label for="postcode" class="error">Please enter your post code.</label> <input class="text" type="text" id="postcode" name="postcode" value="<?=$fields['postcode']?>"> <label for="daynum">Daytime Number:*</label> <label for="daynum" class="error">Please enter your number.</label> <input class="text" type="text" id="daynum" name="daynum" value="<?=$fields['daynum']?>"> <label for="evenum">Evening Number:</label> <input class="text" type="text" id="eve-num" name="evenum"> <label for="email">Email Address:</label> <input class="text" type="text" id="email" name="email"> </fieldset> <fieldset> <label>Cara Glass Product:</label> <label for="check[]" class="error">Please choose a product.</label> <div id="product"> <div class="radio-btn"> <label for="conservatory">Conservatory</label> <input type="checkbox" value="conservatory" id="conservatory" name="product[]" validate="required:true"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="windows">Windows</label> <input type="checkbox" value="windows" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="fascias">Fascias</label> <input type="checkbox" value="fascias" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="doors">Doors</label> <input type="checkbox" value="doors" name="product[]" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="rooftrim">Rooftrim</label> <input type="checkbox" value="rooftrim" name="product[]" /> </div><!--radio-btn--> </div><!--product--> <label for="information">Additional Information:</label> <textarea id="information" name="information"></textarea> </fieldset> <fieldset> <p>How Did You Hear About Us?</p> <div id="how"> <div class="radio-btn"> <label for="internet">Internet</label> <input type="radio" value="internet" id="internet" name="how"/> </div><!--radio-btn--> <div class="radio-btn"> <label for="letter">Marketing Letter</label> <input type="radio" value="letter" id="letter" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="referral">Referral</label> <input type="radio" value="referral" id="referral" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="advertising">Advertising</label> <input type="radio" value="advertising" id="advertising" name="how" /> </div><!--radio-btn--> <div class="radio-btn"> <label for="vans">Our Vans</label> <input type="radio" value="vans" id="vans" name="how" /> </div><!--radio-btn--> </div><!--how--> <p class="submit">Once we have received your details we will call you to arrange a convenient time</p> </fieldset> <input type="submit" name="submit" value="SUBMIT" /> </form> |