Creating a form...

Status
Not open for further replies.

CrazeD

Fully Optimized
Messages
3,736
Location
Maine
Ok, I'm having a helluva time creating forms for my site. Basically, I just want to make a simple form for use as a joining application, for my clan website. The website software is IPB 2.1.7

I suck at PHP, and really don't know much off the top of my head.

I found a script that I'd like to use, but I can't get it to work. It is supposed to send me an email with the form results, but it doesn't send me an email.

I put this on my page:
Code:
<form method="post" action="contact.php">
Subject:

<input type="text" name="subject" size="20">

Email:
<input type="text" name="email" size="20">

Comments:
<textarea cols="20" rows="5" name="comment"></textarea>

<input type="submit" value=" Submit "> </form>

And made a file called 'contact.php' and uploaded it. Inside, is this:
Code:
<?
$subject = $_POST['subject']; // This is will be the subject of the email
$email = $_POST['email'];
$comments = $_POST['comments'];
$submit = $_POST['submit'];

if($submit)
{
// Replace [email]name@host.com[/email] with your email address!
mail("crazed_rider@yahoo.com", "$subject", "$email", "$comments");

}
?>

Here is a preview of it on my site:
http://www.crazed.clanafterdeath.com/index.php?code=test (note: I just use this for testing :p )

I would REALLY appreciate any help, PLEASE!

Thanks in advance.
 
Hi

In your HTML page, you call the textarea "comment". In your PHP page, you pick up a variable called "comments". Maybe because of that...
Yet, you have to check if the mail() function is allowed on your server.
 
Nasky said:
Hi

Yet, you have to check if the mail() function is allowed on your server.

How might I do that?

EDIT: My site does have webmail, if that helps...
 
PHP:
<?php

mail("crazed_rider@yahoo.com", "test subject", "test message");

?>

Put that in a file, upload to your site, and run it once. Quick way to check if it will email you anything :)

If it doesn't, then your server either doesn't support mail() or something else is going that you probably can't fix.

If it does email you, then the problem lies in your code. I noticed this:

PHP:
mail("crazed_rider@yahoo.com", "$subject", "$email", "$comments");

The parameters for the mail() funciton are: mail( to, subject, message, headers).

It looks like you are placing your comments field as your header parameter.

This may work:


PHP:
mail("crazed_rider@yahoo.com", "$subject", "$comments");

I didn't want to add your $email variable in there because you would have to sanitize it to protect from header injection but that's a whole topic in itself. If you need further help, contact me (via AIM ross2376 or email).

Hope that helps.
 
Thank you very much. This worked:

Code:
<?php



mail("crazed_rider@yahoo.com", "test subject", "test message");



?>

I am very relieved to know that that works, but what is wrong with the code?
 
Status
Not open for further replies.
Back
Top Bottom