Hey, I am trying to write a mail script and it keeps running through the script with no output whatsoever. Do you know what is wrong. I am attaching the script and email form. Thanks!

Form:

<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>

Script:

<?php
 $name=$_POST['name'];
  $email=$_POST['email'];
  $comments=$_POST['comments'];
  $submit=$_POST['submit'];

$to = 'email@email.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';
}

?>

    First, you set $name, $email and $comments, and then, you check if they are set... they will ALWAYS be set !

    You mixed up subject and message... subject should be "Comment from viewer", and message, the other thing...

    Also, you call exit OUTSIDE your if statement, so it will always exit !

    Maybe something like this :

    <?php
    
    if(isset($_POST['submit']) && isset($_POST['name']) && isset($_POST['name']) && isset($_POST['comments']))
    {
        $name       = trim($_POST['name']);
        $email      = trim($_POST['email']);
        $comments   = trim($_POST['comments']);
        if(($name == '') || ($email == '') || ($comments == ''))
        {
            echo 'At least one of the fields is empty.';
        }
        else
        {
            $to         = 'email@email.com';
            $subject    = 'Comment from viewer';
            $message    = "$name commented on your Blogging site\r\nHis email address is: $email \r\nHe had this to say: $comments";
            if(mail($to, $subject, $message))
            {
                echo 'Email sent successfully.';
            }
            else
            {
                echo 'Email couldn\'t be sent.';
            }
        }
    }
    else
    {
        echo 'At least one of the fields isn\'t set.';
    }
    
    ?>
    

      Ok, thanks it must have been that exit that was throwing it off. Anyway, I changed it so that it works and I used it and even your mail form with different email addresses, and they all loop through and say "Email couldn't be sent".

      Why will the email not send?

      Thanks!

        Write a Reply...