Re: Coding for email response forms
| From: | Tom | Date: | Mon, 26 Jan 2009 22:10:28 +0000 |
| Subject: | Re: Coding for email response forms | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287186@lists.php.net to get a copy of this message | ||
"Daniel Brown" <danbrown@php.net> wrote in message
news:ab5568160901261347h1dab427bo29a1313494cd507@mail.gmail.com...
> On Mon, Jan 26, 2009 at 16:34, Tom <obelix16@comcast.net> wrote:
>>
>> Shawn,
>> So would that look something like this:
>> <?
>> if ($_SERVER['REQUEST_METHOD'] == "POST") {
>>
>> // Just to be safe, I strip out HTML tags
>> $realname = strip_tags($realname);
>> $email = strip_tags($email);
>> $feedback = strip_tags($feedback);
>>
>> // set the variables
>> // replace $me@mysite.com with your email
>> $sendto = "$me@mysite.com";
>> $subject = "Sending Email Feedback From My Website";
>> $message = "$realname, $email\n\n$feedback";
>>
>> // send the email
>> mail($sendto, $subject, $message);
>>
>> }
>> ?>
>
> For processing once it reaches the server, yes - almost exactly.
> A few recommended changes though:
>
> * Change <? to <?php for compatibility across servers with
> different PHP configurations.
> * Change your if() to if($_POST['realname'])
> * DO NOT rely on register_globals - it's insecure and will
> soon be phased-out of PHP. Instead, using your code:
> $realname = strip_tags($_POST['realname']);
> * Use explicit headers with mail(). For example:
> $headers = "From: you@example.com\r\n";
> $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
> mail($sendto,$subject,$message,$headers);
> * Do something (exit, header("Location: otherpage.html")
> redirect, etc.) so that the form doesn't reappear.
>
> Then, either include that code at the top of the file in which
> your HTML resides, or place it in it's own file (for example:
> formproc.php) and change your form tag to:
> <form method="POST" action="formproc.php"
> name="formName"
> id="formName">
>
>
> NB: My original responses that this wasn't PHP-related was based
> on your original message, saying that your "submit button" wasn't
> working, and then including HTML and JavaScript code only. It didn't
> appear as though it had anything to do with PHP. Getting a good
> answer is best-achieved by asking a well-formed question.
>
> --
> </Daniel P. Brown>
> daniel.brown@parasane.net || danbrown@php.net
> http://www.parasane.net/ ||
> http://www.pilotpig.net/
> Unadvertised dedicated server deals, too low to print - email me to find
> out!
Us newbies don't always phrase the questions right but you & Shawn answered
my question. Just have to try it out now.
Thanks
T