PHP noob - help

Associate
Joined
6 Jan 2006
Posts
803
Location
Ayy
Hey guys, can't seem to get my php send mail form to work, althoiugh i've had it working fine in the past which is odd.

For some reason though, it just wont send an email, although it appears to be working fine when you fill it out.

Here is my HTML code:

Code:
<p>Your Name<br/>
<input name="name" type="text" size="60" />
</p>
<form method="post" action="sendmail.php">
<p>&nbsp;</p>
<p>E-mail Address<br />
<input name="email" type="text" id="email" size="60" />
</p>
<p>&nbsp;</p>
<p>Subject:<br />
<input name="subject" type="text" id="subject" size="60" />
</p>
<p>&nbsp;</p>
<p>Message<br />
<textarea name="additional" rows="8" cols="57"></textarea>
</p>
<p>
<input name="submit" type="image" src="Images/submit.png" />
</p>

And here is my php code for sendmail.php:

Code:
<?php
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  $additional = $_REQUEST['additional'] ;

  if (!isset($_REQUEST['email'])) {
    header( "[email protected]" );
  }

  else {
  	mail( "[email protected]", "Some feedback!",
    	"$message\nSubject:\n $subject \nMessage:\n $additional", 
		"From: $name <$email>" );
  	header( "[email protected]" );
  }
?>

Thanks for any help, but i really am clueless about php.
 
Few errors i can see through my first glance through:

1) The name input isn't within the <form> tag so it wont be sent to the server.
2) The <form> tag doesn't have an end tag so at the moment it wont be sending anything. Try closing the form with a </form> after the last input field.

That should get it working at least :)
 
For your header tags you should use the following format:

PHP:
header( 'Location: http://www.google.co.uk' );

Personally I always set headers as follows, always works for me:

PHP:
$headers .= 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
    $headers .= "From: [email protected]" . "\n";

    $send_mail = mail($to, $subject, $messager, $headers);

It's also worth making your documents validate too :)
 
Thanks for the replies.

Tillus:

I did have a closing </form> tag, I just forgot to copy it over, so my bad,
but I did fix the name tag so it was within the <form> tag, didn't change anything unfortunatley.

and i'll try to use those header tags suarve, so thanks for that.

Anyway after finding that nothing worked, I changed the request tags, to post tags instead, again didn't really change anything :(

This is my code to date, so any input would be great.

PHP:
<?php
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $subject = $_POST['subject'] ;
  $message = $_POST['message'] ;
  $additional = $_POST['additional'] ;

  if (!isset($_REQUEST['email'])) {
  header( 'Location: http://www.abc.com/feedback.html' );
  }
  elseif (empty($name) || empty($email) || empty($subject) || empty($additional)) {
  header( 'Location: http://www.abc.com/error.html' );
  }
  else {
  mail( "[email protected]", "Some feedback",
    	"$message
		 \nSubject:\n $subject 
		 \nMessage:\n $additional", 
		"From: $name <$email>" );
  header( 'Location: http://www.abc.com/thankyou.html' );
  }
?>

And this is the HTML:

Code:
<form method="post" action="sendmail.php">

<p>Your Name</p>

<input name="name" type="text" id="name" size"60" />

<p>E-mail Address</p>

<input name="email" type="text" id="email" size"60" />

<p>Subject</p>

<input name="subject" type="text" id="subject" size"60" />

<p>Message</p>

<textarea name="additional" type="text" id="additional" rows="8" cols="57"></textarea>

<input type="image" name="submit" src="images/submit.png" />

</form>
 
A longshot, but it might not like the the new lines in your message arguement.


Try creating a new varibale for this:

PHP:
$myMessage  = $message . '<br /><br />Subject: ' . $subject .  '<br /><br />Message: ' . $additional; 

mail($to, $subject, $myMessage, $headers);

Also, are you sending this locally via xampp? If so you need to set your your mail server info in php.ini for the mail function to work.
 
Last edited:
Back
Top Bottom