PERFECTPHP E-mail Receive Form Electronic Content TextFrequently Asked Questionsversion | wrong | 404 | modify | send | email | bots | spam | validation | from | header | helpQ: The script doesn't work. What's happening? A: Be sure your web site is running PHP 4.1 or later. A quick way to verify that is to go to Netcraft and use the "What's that site running?" feature to find out what your server is running. A more robust route is to use the phpinfo() function as shown in a Code Newbie tutorial. Q: Yeah, I'm running PHP 4. The script doesn't work. What's wrong? A: Have you made significant customizations to the script? It's fine to make changes, but first get the script working in its simple form. Put the "feedback.php" file in the same folder as your HTML file. After you have the simple case working, go ahead and add customizations and move things around. Q: Why do I get a page not found (404) error when I click submit? A: The "feedback.php" file must be accessible to your browser. You can test this by opening the URL to your PHP file in your browser. For example, if the URL for your HTML file is "http://www.yourdomain.com/xyz/contact.html" and the action for its form is "feedback.php", then test by opening "http://www.yourdomain.com/xyz/feedback.php" in your browser. You should immediately be redirected to the thank you page. Q: What's with this "Cannot modify header information - headers already sent..." warning? A: This error is almost always the result of a previous error. A prior error, like forgetting the ";" at the end of a PHP line, caused PHP to send out a web page displaying an error message, and that web page has a header. The "header()" command at the end of the PERFECT script then fails because a header has already been sent even though the problem is not with the "header()" command itself. Q: How do I send the e-mail message to more than one person? A: Add recipients separated by commas to the "SendTo" line. For example: $SendTo = "feedback@yourdomain.com,hr@yourdomain.com"; Q: The "Thank Your" page shows up correctly, but I don't get any e-mail? A: If the PERFECT script properly redirects you to the confirmation web page but fails to send an e-mail, try replacing the the line: mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); with: mail($SendTo, $SubjectLine, $MsgBody); If that doesn't work, your server is probably configured to block the "mail()" function (see: The PHP Group, SMTP, and WeberDev). Ask your web hosting company if they allow PHP mail. Q: How do I prevent the bots from triggering e-mails? A: As they spider the web, some search engine robots will follow the link in your HTML form causing PERFECT to send an e-mail message with no values. You can solve this annoyance by sending e-mails only if at least one form field has a value. Just before the "mail" line, add a line using the "count()" function as follows: if (count($_POST) > 0) mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); Q: I'm getting attacked by spammers. Help! A: Spammers often look for vulnerable web forms they can trick into causing a server to become an unsuspected spam sender. The attackers use your form to submit the text "bcc:" or "cc:" followed by a test e-mail address in the hope that the form processor inadvertently sends a copy of the message to the test e-mail address. PERFECT appears to be impervious to these attacks, but the resulting barrage of test messages can be annoying. One way to sidestep the attacks without sending a message at all is to replace the "mail" line with the following four lines of code: $Spam = count($_POST) == 0 || stristr($MsgBody, "cc: ") || stristr($MsgBody, "href=") || stristr($MsgBody, "[url"); if (!$Spam) mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); Q: How do I add field validation (error checking) to my form? A: For most web sites, simple client-side validation is plenty sufficient. Client-side validation entails having the user's browser perform the error checking, such as making sure the user entered his or her name, before the data is submitted to PERFECT. This client-side validation is typically done with JavaScript. There is no need to modify the PERFECT script unless you have very stringent validation needs. Q: How do I set the From: field to the submitter's e-mail address? A: Don't. Doing so will give spammers an easy way to inject malicious content into your e-mail headers. Q: How do I add a field to the e-mail header? A: If you have a need to supplement the e-mail header with a field, like "Return-Path" or "Bcc", add a variable to hold the desired value: $ReturnPath = "xyz@yourdomain.com"; Then add the new header to the "mail" command: mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom\r\nReturn-Path: $ReturnPath"); Replace the header name ("Return-Path) and variable ("$ReturnPath") as appropriate for the header field you require. Q: I still need help. Now what? A: Click on the button below to go back to the previous page. Then use the web form (which, of course, is powered by PERFECT) to send me your question. Special thanks to Greg for his technical advice in creating PERFECT. | ||||