Problem with sending of mail after form has been validated

Hi too all.

Thanks very much for reading my post.

I am having an issue with a form. I have got it working to the point where it validates all the areas I need but when I place the mail feature in I start getting parse errors.

I have no errors until I enter the mail () code.

I am new to php and usually outsource my forms, unfortunately my client does not have the budget for it.

Could someone please tell me where I have gone wrong.

Please see code below.

FORM: (the funny :< you see should be < )

<h1>Thank you for your input!</h1>
<h2>Please feel free to send your comments and questions</h2>

<form action=“handle_contact_form.php” method=“post”>

<fieldset><legend>Your contact details</legend>

<label for=“name”>Name:</label><input type=“text” name=“name” size=“30”
maxlength=“60” />
<div class=“tel”>
<label for=“tel”>Tel:</label><input type=“text” name=“tel” size=“30”
maxlength=“60” />
</div>
<label for=“email”>Email:</label><input type=“text” name=“email” size=“30”
maxlength=“60” />
<div class=“fax”>
<label for=“fax”>Fax:</label><input type=“text” name=“fax” size=“30”
maxlength=“60” />
</div>
</fieldset>

<fieldset><legend>Comments</legend>

<label></label> <textarea name=“comments” rows=“4” cols=“62”></textarea><br>

<input checked type=“checkbox” name=“suscribe” value=“Suscribe” /><label for=“suscribe” class=“suscribe”>Subscribe to our email newsletter</label>

&lt;/fieldset&gt; 

<div class=“submit” align=“center”><input type=“submit” name=“submit” value=“Submit” />
</div>

</form>

PHP FORM HANDLER:

<?php #handle_contact_form.php

//validate name
if (!empty($_REQUEST[‘name’])) {
$name = stripslashes($_REQUEST[‘name’]);
}

else {
$name = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Name</font></p>’;
}

//Validate Tel
if (!empty($_REQUEST[‘tel’])){
$tel = stripslashes($_REQUEST[‘tel’]);
}

else {
$tel = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

//Validate email
if (!empty($_REQUEST[‘email’])) {
$email = $_REQUEST[‘email’];
}

else {
$email = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Email Address</font></p>’;
}

//Validate comments
if (!empty($_REQUEST[‘comments’])){
$tel = stripslashes($_REQUEST[‘comments’]);
}

else {
$comments = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

// Validate suscribe
if (!empty($_REQUEST[‘suscribe’])){
$suscribe = stripslashes($_REQUEST[‘suscribe’]);
}

else {
$suscribe = “not suscribe you to our news letter”;

}

// If everything is okay send email and display

if ($name && $email && $comments && $tel) {
$body = " African Agenda has been contacted by ‘{$_POST[‘name’]}’,
from email address ‘{$_POST[‘email’]}’.
<br>
‘{$_POST[‘name’]}’
made the comments<br>
‘{$_POST[‘comments’]}’ \

          &lt;br&gt;
          You have been requested to '{$_POST['suscribe']}'. \

" ;

mail ('admin@reesdynamic.co.za' , 'contact email' , $body );


echo "&lt;p&gt;Thank you, &lt;b&gt;$name&lt;/b&gt;, \

for the following comments: <br />
<tt>$comments</tt></p> ";
echo "<p>We will reply to you at <i>$email</i>.</p>you have asked us to <i>$suscribe</i>
" ;

}

else {
echo “Please go back to fill out the form again” ;
}

?>

Any help or advice would greatly be appreciated.

Thanks very much for your time and help

Mike

I have no errors until I enter the mail () code.

seems to be missing from the above?

hi hash

I have added the mail (‘email’ , ‘subject’ , $body );

I hope this answers you question

Thanks for the reply

what’s the parse error? seems ok

I have since had to add $name = “{$_POST[‘name’]}”;
$email = “{$_POST[‘email’]}”;
$comments = “{$_POST[‘comments’]}” ;
$suscribe = “{$_POST[‘suscribe’]}” ;

above the $body

everytime I have added the mail and above I start getting a parse error at :

else {
echo “Please go back to fill out the form again” ;
}

If I remove the echo and text the parse error moves to the ending of the php :

?>

I am testing on my wamp server, would that be causing the error

I have just run a test on my local server and there are no parse errors with the code from above.

You will also have received a test email from me.

The above code is not the cause for the parse error.

thanks very much pmw57 I really appreciate it.

It must be settings in my mail server and wamp.

Thanks very much pmw57. I have just recieved the test email.

I really appreciate it.

Kindest regards

Mike

You’re welcome. I wish I could help you further on this but at this stage, I’m stumped as to how to help further from here.

I have just uploaded the script and page to my host server and all is working. Thanks very much for the help

I have only one question, did you click the subscribe button, it did not place subscribe or the message to not subscribe. I did pick up my spelling mistakes and have rectified it. I just cant get it to display the subscribe or not subscribe properly

Thanks very much for all the help

I have just got a parse error from my subdomain web server :

Parse error: syntax error, unexpected T_ELSE in /home/reesdyna/public_html/testphpserver/incl_files/handle_contact_form.php on line [B]77

the public_html should not be there. I have not changed anything from the coding you used and it worked first time I tested it.

do you have any suggestions?
[/B]

The code went fro working to not working, so it is a change in the code that caused the error.

Please repost the PHP code. The code also looks a lot better if you use

 tags, with a [ /php] (without the space) at the end.

I have now loaded the pages and script to my online web server

I got the parse error : Parse error: syntax error, unexpected T_ELSE in /home/reesdyna/public_html/testphpserver/incl_files/handle_contact_form.php on line [B]77

The handler is held at : http://www.reesdynamic.co.za/testphpserver/incl_files/handle_contact_form.php

I don’t know why it is giving me the error from the [/B][B]/home/reesdyna/public_html/

The contact form is at : http://www.reesdynamic.co.za/testphpserver/incl_files/contact_orig.incl.html

I am now lost as to why I would get this error.

do you perhaps have any suggestions.

Thanks very much for all you help

[/B]

<?php #handle_contact_form.php

//validate name
if (!empty($_REQUEST[‘name’])) {
$name = stripslashes($_REQUEST[‘name’]);
}

else {
$name = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Name</font></p>’;
}

//Validate Tel
if (!empty($_REQUEST[‘tel’])){
$tel = stripslashes($_REQUEST[‘tel’]);
}

else {
$tel = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

//Validate email
if (!empty($_REQUEST[‘email’])) {
$email = $_REQUEST[‘email’];
}

else {
$email = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Email Address</font></p>’;
}

//Validate comments
if (!empty($_REQUEST[‘comments’])){
$tel = stripslashes($_REQUEST[‘comments’]);
}

else {
$comments = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

// Validate suscribe
if (!empty($_REQUEST[‘subscribe’])){
$subscribe = stripslashes($_REQUEST[‘subscribe’]);
}

else {
$subscribe = “not suscribe you to our news letter”;

}

// If everything is okay send email and display mesage for viewing

if ($name && $email && $comments && $tel) {

echo "&lt;p&gt;Thank you, &lt;b&gt;$name&lt;/b&gt;, \

for the following comments: <br />
<tt>$comments</tt></p> ";
echo "<p>We will reply to you at <i>$email</i>.</p>you have asked us to <i>$suscribe</i>
" ;

}
$name = "{$_POST['name']}";
$email = "{$_POST['email']}";
$comments = "{$_POST['comments']}" ; 
$subscribe = "{$_POST['subscribe']}" ; 


$body = " African Agenda has been contacted by '{$_POST['name']}', \

from email address ‘{$_POST[‘email’]}’.
<br>
‘{$_POST[‘name’]}’
made the comments<br>
‘{$_POST[‘comments’]}’ \

          &lt;br&gt;
          You have been requested to '{$_POST['subscribe']}'. \

" ;

mail ('admin@reesdynamic.co.za' , 'contact email' , $body );

else {
echo “Please go back to fill out the form again” ;
}

?>

Form:

<form action=“handle_contact_form.php” method=“post”>

<fieldset><legend>Your contact details</legend>

<label for=“name”>Name:</label><input type=“text” name=“name” size=“30”
maxlength=“60” />
<div class=“tel”>
<label for=“tel”>Tel:</label><input type=“text” name=“tel” size=“30”
maxlength=“60” />
</div>
<label for=“email”>Email:</label><input type=“text” name=“email” size=“30”
maxlength=“60” />
<div class=“fax”>
<label for=“fax”>Fax:</label><input type=“text” name=“fax” size=“30”
maxlength=“60” />
</div>
</fieldset>

<fieldset><legend>Comments</legend>

<label></label> <textarea name=“comments” rows=“4” cols=“62”></textarea><br>

<input checked type=“checkbox” name=“suscribe” value=“Suscribe” /><label for=“subscribe” class=“suscribe”>Subscribe to our email newsletter</label>

&lt;/fieldset&gt; 

<div class=“submit” align=“center”><input type=“submit” name=“submit” value=“Submit” />
</div>

</form>

Sorry didn’t see your reply

do I perhaps need to set the server settings for mail on my web server ?

Just after the mail command, it looks like you’re missing a closing brace just before the else

Update it to this:


} else {

I see I missed a spelling mistake and have changed it on my web server but still the same

Let me know how it goes when you’ve resolved the else condition.

I have changed the } else {

I had closed it before the email code section.

It now works but does not send the email and keeps telling my to go back and fill out the form

Below is the code:

<?php #handle_contact_form.php

//validate name
if (!empty($_REQUEST[‘name’])) {
$name = stripslashes($_REQUEST[‘name’]);
}

else {
$name = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Name</font></p>’;
}

//Validate Tel
if (!empty($_REQUEST[‘tel’])){
$tel = stripslashes($_REQUEST[‘tel’]);
}

else {
$tel = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

//Validate email
if (!empty($_REQUEST[‘email’])) {
$email = $_REQUEST[‘email’];
}

else {
$email = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Email Address</font></p>’;
}

//Validate comments
if (!empty($_REQUEST[‘comments’])){
$tel = stripslashes($_REQUEST[‘comments’]);
}

else {
$comments = NULL;
echo ‘<p><font color=“red”>You forgot to enter your Telephone Number</font></p>’;
}

// Validate suscribe
if (!empty($_REQUEST[‘subscribe’])){
$subscribe = stripslashes($_REQUEST[‘subscribe’]);
}

else {
$subscribe = “not suscribe you to our news letter”;

}

// If everything is okay send email and display mesage for viewing

if ($name && $email && $comments && $tel) {

echo "&lt;p&gt;Thank you, &lt;b&gt;$name&lt;/b&gt;, \

for the following comments: <br />
<tt>$comments</tt></p> ";
echo "<p>We will reply to you at <i>$email</i>.</p>you have asked us to <i>$subscribe</i>
" ;

$name = "{$_POST['name']}";
$email = "{$_POST['email']}";
$comments = "{$_POST['comments']}" ; 
$subscribe = "{$_POST['subscribe']}" ; 


$body = " African Agenda has been contacted by '{$_POST['name']}', \

from email address ‘{$_POST[‘email’]}’.
<br>
‘{$_POST[‘name’]}’
made the comments<br>
‘{$_POST[‘comments’]}’ \

          &lt;br&gt;
          You have been requested to '{$_POST['subscribe']}'. \

" ;

mail ('admin@reesdynamic.co.za' , 'contact email' , $body );

} else {
echo “Please go back to fill out the form again” ;
}

?>

Form:

<h1>Thank you for your input!</h1>
<h2>Please feel free to send your comments and questions</h2>

<form action=“handle_contact_form.php” method=“post”>

<fieldset><legend>Your contact details</legend>

<label for=“name”>Name:</label><input type=“text” name=“name” size=“30”
maxlength=“60” />
<div class=“tel”>
<label for=“tel”>Tel:</label><input type=“text” name=“tel” size=“30”
maxlength=“60” />
</div>
<label for=“email”>Email:</label><input type=“text” name=“email” size=“30”
maxlength=“60” />
<div class=“fax”>
<label for=“fax”>Fax:</label><input type=“text” name=“fax” size=“30”
maxlength=“60” />
</div>
</fieldset>

<fieldset><legend>Comments</legend>

<label></label> <textarea name=“comments” rows=“4” cols=“62”></textarea><br>

<input checked type=“checkbox” name=“subscribe” value=“Subscribe” /><label for=“subscribe” class=“suscribe”>Subscribe to our email newsletter</label>

&lt;/fieldset&gt; 

<div class=“submit” align=“center”><input type=“submit” name=“submit” value=“Submit” />
</div>

</form>

Thanks so much for all the help and all of your time on this