cboscia Posted April 16, 2013 Share Posted April 16, 2013 Hi, I have made my company website in Adobe Muse (please don't throw things at me). It can be found at this link: http://www.inspirecreativeworks.com. I made a form on the Contact page using HTML, and it looks exactly like I needed it to look. I was told in order to make the form send the info to my email address, I had to script some php. If you fill out the form, it gives me this error: Parse error: syntax error, unexpected T_VARIABLE in /home/content/i/n/s/inspire/html/send_form_email.php on line 4 I know nothing about php. I have attached two files. One is a simple text file so you can see the html of the actual form. The other is a.php file with my code in it. The idea here is to get the info from the form sent to my email address, AND black spam from getting into my email and such. I was told that code is also in my php doc. So the question is why isn't this working? Any help from you guys would be greatly appreciated. And if the php is just totally off, can someone supply a link to a php script that WOULD work? Thank you and please, be gentle! Chris html.rtf send_form_email.php Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/ Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 You can actually make an HTML form send the data to an email address by setting the action attribute to a mailto link: <form action="mailto:email@aol.com"> As far as your error. I don't see anything syntactically wrong on line 4. I think the error might actually be from unexpected whitespace characters, possibly from the editor you used. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425078 Share on other sites More sharing options...
davidannis Posted April 16, 2013 Share Posted April 16, 2013 I opened the file and you do have a white space character that sows up at the beginning of lines as a little cross in my IDE when I display whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425087 Share on other sites More sharing options...
davidannis Posted April 16, 2013 Share Posted April 16, 2013 You can actually make an HTML form send the data to an email address by setting the action attribute to a mailto link: <form action="mailto:email@aol.com"> As far as your error. I don't see anything syntactically wrong on line 4. I think the error might actually be from unexpected whitespace characters, possibly from the editor you used. I have heard that the mailto: action type is not always reliable and the reasoning makes sense to me. I often use computers that don't have a mail client configured. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425088 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 So does anyone know what code WOULD work for this to be effective? I have heard the mailto command does work, but it is not secure and your email will be overrun by spam, getting hundreds of emails daily. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425104 Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 As mentioned, your code seems to be fine. You need to get rid of all the strange whitespace characters. What text editor did you save the PHP file with? Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425110 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 I copied the code and pasted into TextEdit on a mac, then pasted it into Dreamweaver. How do I see these white spaces? Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425115 Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 It looks like it is a multibyte UTF-8 encoded character (xA0 non-breaking space). If you have the ability in one of your text editors to change the encoding to UTF-8, you should be able to see them and replace them. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425117 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 Ok, that's like a different language to me. So let's try this... attached is a screen shot of the code, opened in Dreamweaver. Can you tell me what to delete in each line? And keep in mind, I have no idea what UTF-8 or an xA0 non breaking space is. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425123 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 Sorry, here is the attachment... Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425124 Share on other sites More sharing options...
davidannis Posted April 16, 2013 Share Posted April 16, 2013 if you delete the leading whitespace on the lines with red on the left (and then reformat just to make it readable) it should be OK I think. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425128 Share on other sites More sharing options...
davidannis Posted April 16, 2013 Share Posted April 16, 2013 I did it for you send_form_email1.php Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425133 Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 These characters are actually on EVERY line, not just the red ones. Davidannis is right though; delete all the whitespace in front of every line and use spaces or tabs to format it the way you want. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425136 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 davidannis - You are the fucking man. It worked. Thank you VERY much! Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425138 Share on other sites More sharing options...
ignace Posted April 16, 2013 Share Posted April 16, 2013 (edited) So does anyone know what code WOULD work for this to be effective? I have heard the mailto command does work, but it is not secure and your email will be overrun by spam, getting hundreds of emails daily. If your form isn't protected it won't make any difference whether they mail to you directly or through your form. Also I can send your form by simply making requests to: send_form_email.php?email=t@t.tPut that in a loop and call it say 99999999999999 times? You are gonna have one lovely inbox. Edited April 16, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425149 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 ignace - I heard the same thing. However, putting the $field=filter_var($field, FILTER_SANITIZE_EMAIL); command in there doesn't stop it? Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425175 Share on other sites More sharing options...
cboscia Posted April 16, 2013 Author Share Posted April 16, 2013 davidannis - This works now like I said, but when I get the email, it only shows the content of the message. Is there a way I can have it show the name, company name and phone number as well? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425182 Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 The variables like $_REQUEST['email'] correspond directly to the "name" attributes of your input elements on your form. You can get the values of these by using that name in the $_REQUEST variable just like the others: $message = $_REQUEST['message'] ; $message .= "\r\nTelephone:" . $_REQUEST['telephone']; Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425193 Share on other sites More sharing options...
davidannis Posted April 16, 2013 Share Posted April 16, 2013 If you just want a secure formmail script, I would suggest using http://www.tectite.com/ instead of coding it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425208 Share on other sites More sharing options...
cboscia Posted April 17, 2013 Author Share Posted April 17, 2013 Lemmin - I did that and the form still works, but nothing is displayed except the message. What's wrong with this? See attached... send_form_email.php Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425230 Share on other sites More sharing options...
jcbones Posted April 17, 2013 Share Posted April 17, 2013 See if this works for you: <?php session_start(); function spamcheck($field) { $field=filter_var($field, FILTER_SANITIZE_EMAIL); if(filter_var($field, FILTER_VALIDATE_EMAIL) && empty($_SESSION['mail_sent'])) { $_SESSION['mail_sent'] = 1; return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) { $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "Invalid input"; } else { $name = $_REQUEST['name'] ; $company_name = $_REQUEST['company name'] ; $email = $_REQUEST['email'] ; $telephone = $_REQUEST['telephone'] ; $message = $_REQUEST['message'] ; $content = <<<EOF Name: {$name} Company: {$company_name} Email: {$email} Telephone: {$telephone} ------------------------------------------------------- {$message} EOF; mail("cboscia@inspirecreativeworks.com", "I am interested in Inspire Creative Works $subject", $content, "From: $email" ); echo "Thank you for using our mail form"; } } else { echo "<form method='post' action='send_form_email.php'> Email: <input name='email' type='text'><br> Subject: <input name='subject' type='text'><br> Message:<br> <textarea name='message' rows='15' cols='40'> </textarea><br> <input type='submit'> </form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425234 Share on other sites More sharing options...
cboscia Posted April 17, 2013 Author Share Posted April 17, 2013 Jesus christ. Now it says invalid input when I filled the form out. It worked the first time I used it, now it doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425243 Share on other sites More sharing options...
davidannis Posted April 17, 2013 Share Posted April 17, 2013 It will say invalid input if you try to send it twice because of the spam check. If you close and reopen your browser you'll get a new session and it will let you send again. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425343 Share on other sites More sharing options...
ignace Posted April 17, 2013 Share Posted April 17, 2013 ignace - I heard the same thing. However, putting the $field=filter_var($field, FILTER_SANITIZE_EMAIL); command in there doesn't stop it? Try it. And no you are only verifying it's e-mail-ish. It does nothing against making sure the script isn't executed repeatedly or sending mass mails. Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425429 Share on other sites More sharing options...
ignace Posted April 17, 2013 Share Posted April 17, 2013 (edited) If you close and reopen your browser you'll get a new session and it will let you send again. Which won't help secure your form, a script doesn't have cookies/sessions, so you are only blocking any users that may want to send you a second e-mail. A bot will still simply send out a million mails. Edited April 17, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/277011-someone-please-help-me/#findComment-1425430 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.