Jump to content

Form to mail trouble :(


moltenice

Recommended Posts

Hi! I was looking for some help in mailing a form on my website to myself. i created one but i think there is a glitch in my coding. Can someone please tell me how to fix it?

My Codes:

HTML:

[code]

<form method="POST" action="http://moltenice.9999mb.com/Login.php">

<p>Login:<br>
<input type="text" name="name">
<p>Password:<br>
<input type="text" name="age">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>

[/code]


And my PHP:

[code]

<?
 
// get posted data into local variables
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
$Login = Trim(stripslashes($_POST['Login']));
$Password = Trim(stripslashes($_POST['Password']));

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body);

// redirect to success page
if ($success){
  echo "Done, Thank You";

      } else
        echo "An error occurred! Please try again.";

?>

[/code]

It always gives me An Error Occured echo :(

can someone tell me what I did wrong??

[move]Thanks!![/move]
Link to comment
Share on other sites

two things that i noticed.........

1.
[code]
$Login = Trim(stripslashes($_POST['Login'])); //your form variable name is not 'Login', it is 'name'
$Password = Trim(stripslashes($_POST['Password'])); //form variable is 'age' not 'Password'
[/code]
2.
[code]
// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;//needs to be $Login
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;//needs to be $Password
$Body .= "\n";
[/code]
Link to comment
Share on other sites

Oh lool i realise wats hppnin... i changed the variables :D

but it still echoes (error, please try again)...

this is what I did:
----------------------------------------
HTML:
----------------------------------------
<form method="POST" action="http://moltenice.9999mb.com/Login.php">
<p>Name:<br>
<input type="text" name="name">
<p>Age:<br>
<input type="text" name="age">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>
----------------------------------------
PHP:
----------------------------------------
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
$Login = Trim(stripslashes($_POST['name']));
$Password = Trim(stripslashes($_POST['age']));

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body);

// redirect to success page
if ($success){
  echo "Done, Thank You";

      } else
        echo "An error occurred! Please try again.";

?>
----------------------------------------

Wat else hve I done wrong :(

plz hlp... thx ;)

BTW plz do not tell me to use a generator or something similar. I really wanna learn PHP and thought this would be the easiest way to try...

thx
Link to comment
Share on other sites

ARRG... it still gives me error echo :(    :o

my latest:

HTML:
<form method="POST" action="http://moltenice.9999mb.com/Login.php">
<p>Name:

<input type="text" name="name" value="">
<p>Age:

<input type="text" name="age" value="">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>

PHP:
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
$Login = Trim(stripslashes($_POST['name']));
$Password = Trim(stripslashes($_POST['age']));

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body);

// redirect to success page
if ($success){
  echo "Done, Thank You";

      } else
        echo "An error occurred! Please try again.";

?>

Sorry for this guys... im a n00b.

BTW... thx to all whove tried helpin me ;)


Plz help.. thx  :D
Link to comment
Share on other sites


What is this

<form method="POST" action="http://moltenice.9999mb.com/Login.php">  ???

in action just use this filename where you want to perform the action . no need to pass all the URL.
If action is in same page just use

action="<?echo $PHP_SELF;?>"
Link to comment
Share on other sites

[quote author=joshi_v link=topic=114555.msg466456#msg466456 date=1163252056]

What is this

<form method="POST" action="http://moltenice.9999mb.com/Login.php">  ???

in action just use this filename where you want to perform the action . no need to pass all the URL.
If action is in same page just use

action="<?echo $PHP_SELF;?>"
[/quote]

actually, i just upload the php to that site. I run HTML from my desktop as I think i do not need to upload it as well. So i put the complete link. could this be the reason why it doesn't work?? Plz let me know...

If not... plz tell me wat I have done wrong... thx ;)

(P.S. perhaps 9999mb.com isn't a good host?? maybe someone could upload the script to theirs and see if it worked?? THX!!!)
Link to comment
Share on other sites

Here is the PHP part of your script where you had an error:

[code]
PHP:
<?

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $Login; //
$Body .= "\n";
$Body .= "age: ";
$Body .= $Password;
$Body .= "\n";
[/code]

Is everything working now?  ;D
Link to comment
Share on other sites

Is this your last post?

[quote author=moltenice link=topic=114555.msg466454#msg466454 date=1163251622]
ARRG... it still gives me error echo :(    :o

my latest:

HTML:
<form method="POST" action="http://moltenice.9999mb.com/Login.php">
<p>Name:

<input type="text" name="name" value="">
<p>Age:

<input type="text" name="age" value="">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>

PHP:
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
$Login = Trim(stripslashes($_POST['name']));
$Password = Trim(stripslashes($_POST['age']));

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body);

// redirect to success page
if ($success){
  echo "Done, Thank You";

      } else
         echo "An error occurred! Please try again.";

?>

Sorry for this guys... im a n00b.

BTW... thanks to all whove tried helpin me ;)


please help.. thanks  :D
[/quote]
Link to comment
Share on other sites

[quote author=moltenice link=topic=114555.msg466454#msg466454 date=1163251622]
ARRG... it still gives me error echo :(    :o

my latest:

HTML:
<form method="POST" action="http://moltenice.9999mb.com/Login.php">
<p>Name:

<input type="text" name="name" value="">
<p>Age:

<input type="text" name="age" value="">
<p><input type="submit" name="submit" value="Submit">
</form>
<p>

PHP:
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
$Login = Trim(stripslashes($_POST['name']));
$Password = Trim(stripslashes($_POST['age']));

// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "age: ";
$Body .= $age;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body);

// redirect to success page
if ($success){
  echo "Done, Thank You";

      } else
         echo "An error occurred! Please try again.";

?>

Sorry for this guys... im a n00b.

BTW... thanks to all whove tried helpin me ;)


please help.. thanks  :D
[/quote]

Yess lool... plz hlp... thx
Link to comment
Share on other sites

Well, in this part of your code:

PHP:
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
[color=red]$Login[/color] = Trim(stripslashes($_POST['name']));
[color=red]$Password[/color] = Trim(stripslashes($_POST['age']));


you created the variables: $Login and $Password.
$Login is a value for the name field and $Password is a value for age field.
When user enters data in form into age and name fields and submits the form, $Login holds the name value and $Password holds the age value. So, now you have two variables: $Login and $Password.

In the second part of your code:


// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= [color=red]$name;[/color]
$Body .= "\n";
$Body .= "age: ";
$Body .= [color=red]$age;[/color]
$Body .= "\n"


you are preapering the email body which will you send to yourself. For name value you use $name and for age value you use $age. But the name value was assigned to $Login so no $name variable exist in your script. The age value was assigned to $Password variable, so no $age variable exist. That's why you need to change the $name to $Login and $age to $Password in the second part of the code.

Or, if you want that the second part be untouched, change the first part's $Login into $name and $Password into $age:


PHP:
<?
$EmailFrom = "dabrainstabber@gmail.com";
$EmailTo = "dabrainstabber@gmail.com";
$Subject = "FON Pass";
[color=red]$Login[/color] = Trim(stripslashes($_POST['name']));
[color=red]$Password[/color] = Trim(stripslashes($_POST['age']));

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.