# PHP problem



## Msap14 (Jul 15, 2010)

The following code appears fine in Firefox but not in internet explorer, i am pretty new to php so if you could help me figure out why this is it would be appreciated.  What I'm trying to do, maybe im doing the wrong thing completely, is to have a form that when filled out and submitted it sends an email with the details.


</php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "someone@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form

  echo "<form method='post' action='mailform.php'>
  Name: <input name='name' type='text' />
  Phone number: <input name='phone number' type='text' />
  <br>email: <input name='email' type='text' /></br>
  How many sets of clubs?: <select name="number of club sets"><br />
  <option>1</option>
  <option>2+</option>
  <option>5+</option>
  <option>10+</option>
  </select>
  <br />
  How many days? <select name"number of days"><br />
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7+</option>
  </select>
  <br />
  Starting Date: <input name='starting date' type='text' />
  <br />
  Specail requests:
  <br />
  <textarea name='speacial requests' rows='15' cols='40'>
  </textarea>
  <br />
  <input type='submit' />
  </form>

P.S. I know the beginning and end part of the code is messed up (i was playing with it to see if it changed anything) but if someone could also tell me what the proper starting point of this and endpoint of this is it would be appreciated (previously in IE some symbols like ;/?> or something appeared after the form.


----------



## parelem (Jul 15, 2010)

try this


```
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
	//send email
	$email = $_REQUEST['email'];
	$subject = $_REQUEST['subject'];
	$message = $_REQUEST['message'];
	mail( "someone@example.com", "Subject: $subject",
		$message, "From: $email" );
	echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form

echo "<form method='post' action='mailform.php'>
Name: <input name='name' type='text' />
Phone number: <input name='phone number' type='text' />
<br>email: <input name='email' type='text' /></br>
How many sets of clubs?: <select name='number of club sets'><br />
<option>1</option>
<option>2+</option>
<option>5+</option>
<option>10+</option>
</select>
<br />
How many days? <select name'number of days'><br />
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7+</option>
</select>
<br />
Starting Date: <input name='starting date' type='text' />
<br />
Specail requests:
<br />
<textarea name='speacial requests' rows='15' cols='40'>
</textarea>
<br />
<input type='submit' />
</form>";

?>
```


----------



## FordGT90Concept (Jul 16, 2010)

All those apostrophes are improper for HTML.  I would do it like so:


```
<?php 
if (isset($_REQUEST['email'])) 
//if "email" is filled out, send email 
{ 
    //send email 
    $email = $_REQUEST['email']; 
    $subject = $_REQUEST['subject']; 
    $message = $_REQUEST['message']; 
    mail( "someone@example.com", "Subject: " . $subject, 
        $message, "From: " . $email); 
    echo "Thank you for using our mail form"; 
} 
else
{
//if "email" is not filled out, display the form 
	?>
<html>
<head></head>
<body>
	<form method="POST" action="mailform.php"> 
	Name: <input name="name" type="text" /> 
	Phone number: <input name="phone number" type="text" /> 
	<br>email: <input name="email" type="text" /></br> 
	How many sets of clubs?: <select name="number of club sets"><br /> 
	<option>1</option> 
	<option>2+</option> 
	<option>5+</option> 
	<option>10+</option> 
	</select> 
	<br /> 
	How many days? <select name="number of days"><br /> 
	<option>1</option> 
	<option>2</option> 
	<option>3</option> 
	<option>4</option> 
	<option>5</option> 
	<option>6</option> 
	<option>7+</option> 
	</select> 
	<br /> 
	Starting Date: <input name="starting date" type="text" /> 
	<br /> 
	Specail requests: 
	<br /> 
	<textarea name="speacial requests" rows="15" cols="40"> 
	</textarea> 
	<br /> 
	<input type="submit" /> 
	</form>
</body></html>
<?php } ?>
```
Additionally, you need to verify all inputs are good before sending it and you need to complete the $message variable (there is no variable named "message").


----------



## Msap14 (Jul 19, 2010)

parelem said:


> try this
> 
> 
> ```
> ...



this showed up only in firefox


----------



## Msap14 (Jul 19, 2010)

> All those apostrophes are improper for HTML. I would do it like so:
> 
> PHP Code:
> <?php
> ...



Appeared in both firefox and IE explorer thanks.


----------



## Msap14 (Jul 22, 2010)

> <?php
> if (isset($_REQUEST['email']))
> //if "email" is filled out, send email
> {
> ...



i believe i have the code correct now. I get a 404 page not found, Not Found
The requested URL /mailform.php was not found on this server, error message when submit is clicked. is there something i have to set up to enable php emailing?


----------



## Disparia (Jul 22, 2010)

If the file that the code came from is not named "mailform.php", name it that or change the line:

<form method="POST" action="mailform.php">

To

<form method="POST" action="TheRealFilename.php">


Bigger issue though, when using a space with the form element names, need to access $_REQUEST like: $_REQUEST['var_name_with_underscores'] or ideally don't use spaces.


----------



## Kreij (Jul 22, 2010)

Another thought is that you may need the path to the mailform.php file (something like forms\mailform.php) if it's somewhere else on the server.


----------



## FordGT90Concept (Jul 22, 2010)

replace:

```
<form method="POST" action="mailform.php">
```
with:

```
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
```


----------



## Disparia (Jul 22, 2010)

Kreij said:


> Another thought is that you may need the path to the mailform.php file (something like forms\mailform.php) if it's somewhere else on the server.



Kinda would make all that code up at the top a bit superfluous


----------



## Kreij (Jul 23, 2010)

Jizzler said:


> Kinda would make all that code up at the top a bit superfluous




```
if (Tired && BusyAtWork && SkimmingPosts && NotEnoughCoffee)
{
    DontPost();
}
```


----------



## FordGT90Concept (Jul 23, 2010)

That's not PHP. XD


----------

