music_fan01 Posted September 18, 2011 Share Posted September 18, 2011 When I test my php, all of the errors work, but when I actually want to send an email the form doesnt go through and I get the error message 'Please enter a valid e-mail address'? I think I may have something wrong in my mail function. <?php if (empty($_POST['author'])) { $errors[] = 'Please enter a name'; } if (empty($_POST['subject'])) { $errors[] = 'Please enter a subject'; } if (empty($_POST['text'])) { $errors[] = 'Please enter your comments.'; } if (empty($_POST['email'])) { $errors[] = 'Please enter an e-mail'; } else if (!preg_match("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$ ^", $_POST['email'])) { $errors[] = 'Please enter a valid e-mail address'; } if (count($errors) == 0) { // Process form mail("solysol05@gmail.com","Subject: subject", text,"From: author <email>"); echo "Thank you for using our mail form.<br/>"; echo "Your email has been sent."; } else { echo $errors[0]; } ?> Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 18, 2011 Share Posted September 18, 2011 $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: XXXX@XXXXX.com"; $subject = "Your SUBJECT";// $final_message = "MESSAGE "; mail($to, $subject, $final_message, $headers); http://www.w3schools.com/PHP/php_ref_mail.asp Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 18, 2011 Author Share Posted September 18, 2011 Just to make sure I am doing this right, is this the way my final php markup should be? <?php if (empty($_POST['author'])) { $errors[] = 'Please enter a name'; } if (empty($_POST['subject'])) { $errors[] = 'Please enter a subject'; } if (empty($_POST['text'])) { $errors[] = 'Please enter your comments.'; } if (empty($_POST['email'])) { $errors[] = 'Please enter an e-mail'; } else if (!preg_match("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$ ^", $_POST['email'])) { $errors[] = 'Please enter a valid e-mail address'; } if (count($errors) == 0) { // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = "Your SUBJECT";// $final_message = "MESSAGE "; mail($to, $subject, $final_message, $headers); echo $errors[0]; } ?> Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 19, 2011 Share Posted September 19, 2011 1. Can you able to send mail? 2. extra code - using if statement. if (count($errors) == 0) { // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = "Your SUBJECT"; $final_message = "MESSAGE "; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 19, 2011 Share Posted September 19, 2011 just make sure receiver email address included if (count($errors) == 0) { //receiver email address $to=$_POST['email']; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = "Your SUBJECT"; $final_message = "MESSAGE "; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 19, 2011 Author Share Posted September 19, 2011 Now when I test it, I get a blank page. <?php if (empty($_POST['author'])) { $errors[] = 'Please enter a name'; } if (empty($_POST['subject'])) { $errors[] = 'Please enter a subject'; } if (empty($_POST['text'])) { $errors[] = 'Please enter your comments.'; } if (empty($_POST['email'])) { $errors[] = 'Please enter an e-mail'; } else if (!preg_match("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$ ^", $_POST['email'])) { $errors[] = 'Please enter a valid e-mail address'; } if (count($errors) == 0) { //receiver email address $to=$_POST['email']; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = "Your SUBJECT"; $final_message = "MESSAGE "; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } ?> <!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>Contact</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="templatemo_wrapper"> <div id="templatemo_header"> <ul id="social_box"> <li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li> <li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li> </ul> <div id="site_title"> <h1><a href="default.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1> </div> <!-- end of site_title --> </div> <!-- end of templatemo_header --> <!-- end of templatemo_menu --> <div id="templatemo_content_wrapper"> <div id="templatemo_content_top"></div> <div id="templatemo_content"> <h2>Contact</h2> <div class="cleaner_h50"></div> <div id="contact_form"> <h4>Quick Contact</h4> <p align="left">* Required fields.</p> <form method="post" name="ContactForm" id="contact" action="email.php" "> <div class="col_w340 float_l"> <label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> <div class="cleaner_h10"></div> <label for="subject">* Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">* Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> </div> <div class="col_w340 float_r"> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </div> </form> </div> <div class="cleaner"></div> </div> <div id="templatemo_content_bottom"></div> </div> <div id="templatemo_sp_box"> <div class="col_w340 float_l"> </div> </div> <div class="col_w340 float_r"> </div> </div> </div> <div id="templatemo_footer"> Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a> </div> <!-- end of templatemo_footer --> </div> <!-- end of templatemo_wrapper --> </body> </html> Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 19, 2011 Share Posted September 19, 2011 Now when I test it, I get a blank page? means Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 19, 2011 Share Posted September 19, 2011 Number of points I would like to tell you. 1. Naming error – input name and if (empty($_POST['author'])) if (empty($_POST['author'])) label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> 2. Error in email preg_match Now try this code (please enter your email address in the $to variable) <?php if(isset($_POST['submit'])) { if (empty($_POST['name'])) {$errors[] = 'Please enter a name';} if (empty($_POST['subject'])) {$errors[] = 'Please enter a subject';} if (empty($_POST['text'])) {$errors[] = 'Please enter your comments.';} if (empty($_POST['email'])) {$errors[] = 'Please enter an e-mail';} elseif (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['email'])) {$errors[] = 'Please enter a valid e-mail address';} if (count($errors) == 0) { // Your OR Receiver email address $to= your email address; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = $_POST['subject']; $final_message = " Name - " . $_POST['name']. " email - ".$_POST['email']. " Message-".$_POST['text']; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } else { var_dump($errors); } } else { ?> <form method="post" action="email.php"> <label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> <div class="cleaner_h10"></div> <label for="subject">* Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">* Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> <div class="col_w340 float_r"> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </form> <? } ?> PS :This is an example you can do any changes you like. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 19, 2011 Author Share Posted September 19, 2011 Now when I run it, I get Parse error: syntax error, unexpected '@' in /home/a9577046/public_html/email1.php on line 22. Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 20, 2011 Share Posted September 20, 2011 TESTED and works fine. Now when I run it, I get Parse error: syntax error, unexpected '@' in /home/a9577046/public_html/email1.php on line 22. That error is usually as a result of a missing curly bracket , post a bit of code that causes the error. Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 20, 2011 Share Posted September 20, 2011 And don't forgot to change this which will cause an error: $to= your email address; Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 20, 2011 Author Share Posted September 20, 2011 This is the php that I used. I am not too sure, but I think I wasnt suppose to put my email address in the Reply-To. I still keep getting that error. <?php if(isset($_POST['submit'])) { if (empty($_POST['name'])) {$errors[] = 'Please enter a name';} if (empty($_POST['subject'])) {$errors[] = 'Please enter a subject';} if (empty($_POST['text'])) {$errors[] = 'Please enter your comments.';} if (empty($_POST['email'])) {$errors[] = 'Please enter an e-mail';} elseif (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['email'])) {$errors[] = 'Please enter a valid e-mail address';} { if (count($errors) == 0) { // Your OR Receiver email address $to= myemailaddress@gmail.com; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = $_POST['subject']; $final_message = " Name - " . $_POST['name']. " email - ".$_POST['email']. " Message-".$_POST['text']; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } else { var_dump($errors); } } else { ?> <form method="post" action="email.php"> <label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> <div class="cleaner_h10"></div> <label for="subject">* Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">* Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> <div class="col_w340 float_r"> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 20, 2011 Share Posted September 20, 2011 what is the error? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 20, 2011 Author Share Posted September 20, 2011 Parse error: syntax error, unexpected '@' in /home/a9577046/public_html/email1.php on line 22. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 20, 2011 Share Posted September 20, 2011 Because you've left out the quotes to enclose the email address on that line. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 20, 2011 Author Share Posted September 20, 2011 Thanks thats what it was! Now my validation doesnt work. Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 20, 2011 Share Posted September 20, 2011 Thanks thats what it was! Now my validation doesnt work. it is working fine Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 20, 2011 Share Posted September 20, 2011 longer version for you. just copy , enter your email address and run it <?php if(isset($_POST['submit'])) { if (empty($_POST['name'])) {$errors[0] = 'Please enter a name'; echo 'Please enter a name'; } if (empty($_POST['subject'])) {$errors[1] = 'Please enter a subject'; echo 'Please enter a subject';} if (empty($_POST['text'])) {$errors[2] = 'Please enter your comments.'; echo 'lease enter your comments.';} if (empty($_POST['email'])) {$errors[3] = 'Please enter an e-mail'; echo 'Please enter an e-mail';} elseif (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['email'])) {$errors[4] = 'Please enter a valid e-mail address'; echo 'Please enter a valid e-mail address';} if (count($errors) == 0) { // Your OR Receiver email address $to='youremailaddress@domain.com'; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com"; $subject = $_POST['subject']; $final_message = " Name - " . $_POST['name']. " email - ".$_POST['email']. " Message-".$_POST['text']; if (mail($to, $subject, $final_message, $headers) ) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } } else { var_dump($errors); } } else { ?> <form method="post" action="#"> <label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> <div class="cleaner_h10"></div> <label for="subject">* Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">* Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> <div class="col_w340 float_r"> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </ div> </form> <? } ?> for your reading http://www.kirupa.com/web/php_contact_form2.htm http://www.phpeasystep.com/phptu/8.html Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 21, 2011 Author Share Posted September 21, 2011 I went ahead and change some things around. I found an example that writes out the error in red right in the form. So I went ahead tried to combine examples, but in doing so, I think I may have made things worse. I get the error : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9577046/public_html/mail.php on line 39 <?php if(isset($_POST['submit'])) { if ($_POST['name'] != "") { $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if ($_POST['name'] == "") { $errors .= 'Please enter a valid name.<br/><br/>'; } } else { $errors .= 'Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>"; } } else { $errors .= 'Please enter your email address.<br/>'; } if ($_POST['message'] != "") { $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING); if ($_POST['message'] == "") { $errors .= 'Please enter a message to send.<br/>'; } } else { $errors .= 'Please enter a message to send.<br/>'; } if (count($errors) == 0) { // Your OR Receiver email address $to='solysol05@gmail.com'; // Process form $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From:$_POST['name']\r\n Reply-To: $_POST['email'}"; $subject = $_POST['subject']; $message = " Name - " . $_POST['name']. " email - ".$_POST['email']. " Message-".$_POST['text']; if (!$errors) { $mail_to = 'Email: ' . $_POST['email'] . "\n"; $subject = 'New Mail from Form Submission'; $message = 'From: ' . $_POST['name'] . "\n"; $message .= 'Email: ' . $_POST['email'] . "\n"; $message .= 'Homepage: ' . $_POST['homepage'] . "\n"; $message .= "Message:\n" . $_POST['message'] . "\n\n"; mail($to, $subject, $message); if (mail($to, $subject, $message, $headers) ) { echo " Thank you! - Your feedback has been sent! "; } echo "Thank you for your email!<br/><br/>"; } else { echo '<div style="color: red">' . $errors . '<br/></div>'; } else { var_dump($errors); } } else { ?> <form method="post" action="#"> <label for="name">* Name:</label> <input name="name" type="text" class="input_field" id="name" maxlength="40" /> <div class="cleaner_h10"></div> <div class="cleaner_h10"></div> <label for="email">* Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> <div class="col_w340 float_r"> <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </ div> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 21, 2011 Author Share Posted September 21, 2011 I've been looking around and researching, I think my error is caused because I might confusing double quotes with single quotes. Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 21, 2011 Share Posted September 21, 2011 Which is line 39? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted September 21, 2011 Author Share Posted September 21, 2011 This is line 39. // Process form $headers = "MIME-Version: 1.0\r\n"; 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.