Forum Moderators: coopster

Message Too Old, No Replies

formmail issue parse error unexpected T IF

parse error, unexpected T_IF

         

wtwolf6

2:27 am on Mar 11, 2007 (gmt 0)

10+ Year Member



Ok quick question,

My employer is trying to get a contact page working with multiple department contacts

I have a few sites and work on them as a hobby so I was asked if I could help them out.

the form code is as follows


<form action="contact.php" method="POST" onSubmit="return formcheck(this);">
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<td width="30%"><div align="right">Department:</div></td>
<td width="70%">
<select name="department" size="1">
<option value="a" selected>Parts</option>
<option value="b">Sales</option>
<option value="c">Service</option>
<option value="d">Gen. Manager</option>
<option value="e">Receivables</option>
<option value="f">Payables</option>
</select> </td>
</tr>
<tr>
<td width="30%"><div align="right">Full Name:</div></td>
<td width="70%"><input name="name" type="text" size="40" maxlength="100">
</td>
</tr>
<tr>
<td width="30%"><div align="right">Email:</div></td>
<td width="70%"><input name="email" type="text" size="40" maxlength="100">
</td>
</tr>
<tr>
<td><div align="right">Telephone Number:</div></td>
<td><input name="telephone" type="text" size="40" maxlength="100"> </td>
</tr>
<tr>
<td><div align="right">How can we help?</div></td>
<td><textarea name="query" cols="30" rows="7"></textarea> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="submit" type=submit value=Submit>
</div></td>
</tr>
</table>
</form>

this is what it shows after hitting submit

and this is the part of the contact.php that shows the error


<?php

// Error Reporting
error_reporting(E_ALL);

// Receiving variables
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
@$telephone = addslashes($_POST['telephone']);
@$query = addslashes($_POST['query']);

$pfw_header = "From: $email";
$pfw_subject = "Customer Service Contact Form";

$pfw_email_to = (empty($_POST['department']))? 'default' : $_POST['department'];
$email_addresses = array('a' => 'parts@domain.com', 'b' => 'sales@domain.com', 'c' => 'service@domain.com', 'd' => 'taylorabqnm@domain.com', 'e' => 'ar@domain.com', 'f' => 'ap@domain.com', 'default' => 'taylorabqnm@domain.com');

if(!array_key_exists($pfw_email_to, $email_addresses)) {
$pfw_email_to = $email_addresses['default'];
}
else {
$pfw_email_to = $email_addresses[$pfw_email_to];
}

$pfw_message = "Client Name: $name\n"
. "\n"
. "Client Email: $email\n"
. "\n"
. "Client Number: $telephone\n"
. "\n"
. "Comments: $query\n"
if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
};
else {
header("Location: http://www.domain.com/TRE_EMAILSUBMITTED.html") or die('<strong>Thank you for contacting us for more information on our products and services.
We will have someone contact you shortly.</strong>');
}

?>


What am I doing wrong? I have changed it checked and double checked and still have the same parser error.

Please help.

Thanks for your time.
Roger S.

eelixduppy

3:05 am on Mar 11, 2007 (gmt 0)



Welcome to WebmasterWorld [webmasterworld.com], Roger!

You have a semicolon where it is not needed:


if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
}; #<---- excess semicolon on this line

Take out the semicolon after the bracket like this:


if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
}

Some threads you may also be interested in reading:
The Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]
Comabtting Webform Hijack [webmasterworld.com]

Good luck! :)

wtwolf6

3:51 am on Mar 11, 2007 (gmt 0)

10+ Year Member



unfortunatly this did not work my code now looks like this and still gives the same error

"Parse error: parse error, unexpected T_IF in /home/content/html/contact.php on line 35"


if(!mail($pfw_email_to, $pfw_subject, $pfw_message, $pfw_header)) {
die('Error in sending mail.');
}
else {

eelixduppy

3:56 am on Mar 11, 2007 (gmt 0)



hehe, sorry. You are also missing a semicolon on this line right above the "erroneous" if statement:

$pfw_message = "Client Name: $name\n"
. "\n"
. "Client Email: $email\n"
. "\n"
. "Client Number: $telephone\n"
. "\n"
. "Comments: $query\n"[b];[/b]# I added semicolon to end here

wtwolf6

4:07 am on Mar 11, 2007 (gmt 0)

10+ Year Member



Omg, I cant believe I did not see that.

Thank you so much I have read those lines about 500 times.

Thank you

Roger S.