Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is PHP script correct

Status
Not open for further replies.

HigherHigher

IS-IT--Management
Feb 7, 2005
37
CA
Hi, I want to build a form to collect email address. When I tested this script on the browser, it says " the page cannot be found" after I submited my email address. I know both HTML and PHP page up on the server. Is my PHP script correct? Thank you very much for your help.

HTML
<form action="send.php" method="post">

<table width="300" border="0" >
<tr>
<td width="50"></td>
<td width="250" class=""><p class="style6">&nbsp;</p></td>
</tr>
<tr>
<td width="80">Email address:</td>
<td width="120">
<input type="text" name="email" id="email" size="30" maxlength="40">
</td>
</tr>
<tr align="center" valign="middle"><td colspan="2"><input name="submit" type="submit" value="Sign Me Up!"></td>
</tr>
</table>
</form>

PHP script
<?
$email = $_REQUEST['email'] ;
mail( "djm@hotmail.com", "Feedback Form Results",
$message, "From: $email" );
?>
 
You have both PHP and HTML errors. The action is going to send.php, so the PHP code must be on send.php.

As for the PHP part:

Never use request. Its unsafe. You correctly set $email, but $message is still unset if you have register globals off. Also, you shouldn't use double quotes. It slower than single quotes.
 
I can see the errors for HTML. Can you help me to make the correction for my PHP script. Thanks.
 
Code:
PHP script
<?
  $email = $_POST['email'];
  # what about some validation here?
  # You'll get spammed with a form like that...
  mail( 'djm@hotmail.com', 'Feedback Form Results',
    $_POST['message'], 'From: '.$email);
  ?>

It's an ugly SPAMMERs world out there. Validation of the email address is good, also look up if there is something in the message.
 
Hi DR,
Thanks for helping me out.
Yes for validation. I hate spams. What would I do?
 
If there are errors on above HTML tags, please tell me. It is not working at all.
 
Could you give a bit more information than "It is not working at all"?
Any error messages? Can we see the full send.php script?
 
PHP script
<?
$email = $_POST['email'];
# what about some validation here?
# You'll get spammed with a form like that...
mail( 'djm@hotmail.com', 'Feedback Form Results',
$_POST['message'], 'From: '.$email);
?>

It's like the server cannot detect your php script at all.
Maybe the server does not support PHP. I don't know.
 
Write the following script and name it test.php
Code:
<?php
phpinfo();
?>
If that does not produce output with the Zend PHP logo, then your server does not have PHP enabled or doesn't parse it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top