snoggle Posted December 2, 2009 Share Posted December 2, 2009 I'm a newbie and I'm still learning PHP. However this error has me stumped. I've googled, searched the forums, but I can't seem to fix this. I'm sure the fix is obvious, but I so new I really need help. Thanks. Parse error: syntax error, unexpected T_STRING in /public_html/send.php on line 4 <?php error_reporting(E_ALL); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } if($_POST['subject']!=""){ echo 'Dirty Spammer! Your message was NOT sent.'; } else { if( isset($_POST['firstName']) && isset($_POST['lastName']) && isset($_POST['Email']) && valid_email($_POST['Email'])==TRUE && isset($_POST['message']) && strlen($_POST['message'])>15) { $to = '[email protected]'; $headers = 'From: '.$_POST['Email'].''. "\r\n" . 'Reply-To: '.$_POST['Email'].'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Your Simple AJAX Contact Form"; $message = htmlspecialchars($_POST['message']); $spam = $_POST['subject']; if(mail($to, $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. echo 'Thank you '.$_POST['firstName'].'. Your message was sent.'; echo '<noscript> <a href="http://www.yourdomain.com">Back to yourdomain.com</a></noscript>'; } else { echo "Message not sent."; echo "Please make sure you're not running this on localhost and also that you are allowed to run mail() function from your webserver."; } } else { echo "Please make sure you filled in all the required fields, that you entered a valid email and also that your message contains more then 15 characters."; echo "<noscript> Use your browser's back button or <a href=\"http://www.yourdomain.com\">click here</a></noscript> to try again."; } ?> Link to comment https://forums.phpfreaks.com/topic/183774-need-help-with-unexpected-t-string-error/ Share on other sites More sharing options...
premiso Posted December 2, 2009 Share Posted December 2, 2009 Becareful when using $ inside of double quotes as it is interpreted. return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}\$/ix", $str)) ? FALSE : TRUE; Try that and see if you get the same errors (note I escaped the $ by adding a \ infront of it.). Link to comment https://forums.phpfreaks.com/topic/183774-need-help-with-unexpected-t-string-error/#findComment-970007 Share on other sites More sharing options...
mraza Posted December 2, 2009 Share Posted December 2, 2009 <?php error_reporting(E_ALL); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}\$/ix", $str)) ? FALSE : TRUE; } if(empty($_POST['subject'])){ echo 'Dirty Spammer! Your message was NOT sent.'; } else { if( isset($_POST['firstName']) && isset($_POST['lastName']) && isset($_POST['Email']) && valid_email($_POST['Email'])==TRUE && isset($_POST['message']) && strlen($_POST['message'])>15) { $to = '[email protected]'; $headers = 'From: '.$_POST['Email'].''. "\r\n" . 'Reply-To: '.$_POST['Email'].'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Your Simple AJAX Contact Form"; $message = htmlspecialchars($_POST['message']); $spam = $_POST['subject']; if(mail($to, $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. echo 'Thank you '.$_POST['firstName'].'. Your message was sent.'; echo '<noscript> <a href="http://www.yourdomain.com">Back to yourdomain.com</a></noscript>'; } else { echo "Message not sent."; echo "Please make sure you're not running this on localhost and also that you are allowed to run mail() function from your webserver."; } } else { echo "Please make sure you filled in all the required fields, that you entered a valid email and also that your message contains more then 15 characters."; echo "<noscript> Use your browser's back button or <a href=\"http://www.yourdomain.com\">click here</a></noscript> to try again."; } } ?> Link to comment https://forums.phpfreaks.com/topic/183774-need-help-with-unexpected-t-string-error/#findComment-970009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.