php processor does not seem to work: mail form??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

php processor does not seem to work: mail form??

Post by josh22x »

I am trying to write a simple mail form, but when ever the script is processed, nothing is returned, no errors or anything. Is something wrong with my PHP processor or something??

Here is the form and script:

Code: Select all

<form action="mailprocessor.php" method="post">
     
<fieldset class = "fieldset1">
<legend class = "legend">Contact Form</legend>
 
<dt class = "dt">Name</dt>
 
<dd><input class = "text_area" type="text" name="name" maxlength="20" size="20"></dd>
 
<dt class = "dt">Email:</dt>
 
<dd><input class = "text_area" type="text" name="email" maxlength="20" size="20"></dd>
 
<dt class = "dt">Text:</dt>
 
<dd><textarea class = "text_area" name="comments" font-size= 18px" cols = "40" rows = "5">
</textarea></dd>
 
<dd><input class = "text_area" type="submit" value="Register" name="submit"></dd>
 
</fieldset>
</div>
</form>
PHP script:

Code: Select all

<?php
 $name=$_POST['name'];
  $email=$_POST['email'];
  $comments=$_POST['comments'];
  $submit=$_POST['submit'];
  
$to = 'josh22x@gmail.com';
$subject = '$name . "Commented on your Blogging site" . "<br>" . "His email address is:" . $email . 
"He had this to say:" . $comments';
 
$message = 'Comment from viewer';
 
if(isset($name, $email, $comments)) 
{
$sent = mail($to, $subject, $message);
}
else 
{
echo 'Please fill out all of the fields';
}
exit;
 
if($sent)
{
echo 'Mail sent successfully';
}
else
{ 
echo 'Mail Error';
}
?>
 
I believe the script should work - do you know what is wrong?
What perplexes me, is that no errors are returned and no echo statements are produced either.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: php processor does not seem to work: mail form??

Post by Jade »

Are you redirecting to the correct page? Have you tried putting an echo statement outside of the if statements?
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: php processor does not seem to work: mail form??

Post by nowaydown1 »

I would follow Jade's troubleshooting steps. The reason you don't see your messages about mail being sent or not sent is because you have an exit outside any conditionals on line 21. Script execution ends before your if($sent) check ever happens. Hope that helps.

Also, make sure you have something installed to send mail. There have been times when I forgot to install postfix and sat around scratching my head for a minute.
Post Reply