PDA

View Full Version : Contact form - unexpected T_ELSE



ralitza
02-25-2006, 06:49 PM
http://www.iankovi.com/sponsicontact.php

I get Parse error: parse error, unexpected T_ELSE in /home/iankovi/public_html/sponsicontact.php on line 38



<?php
$to = 'iankovi.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$message = wordwrap($message, 85);

if (empty($name) || empty($email) || empty($subject) ||empty($message))
{
echo 'Please fill in and verify all fileds';

if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email']))
{
echo 'Please enter a valid email address.';

} else {

$send=mail("$to", "$email", "$subject", "message");

if($send)
{
echo 'Your message has been sent successfully! A Sponsi representive will get back to you shortly.';

} else {
echo 'There was an error sending the mail, please go back and try again.';

} else {

echo ('

<div id=\"contactleft\">
<h2>Contact customer service</h2>
<span class=\"elevensize\">All fields should be filled in and verified</span>
<form method=\"POST\">
Name: <br />
<input name=\"name\" type=\"text\" class=\"inputlong\" /> <br />
Email Address: <br />
<input name=\"email\" type=\"text\" class=\"inputlong\" /> <br />
Subject: <br />
<input name=\"subject\" type=\"text\" class=\"inputlong\" /> <br />
Detailed Message: <br />
<textarea name=\"message\" cols=\"5\" rows=\"10\" class=\"texarealong\"></textarea>
<br />
<input name=\"send\" type=\"submit\" id=\"contantbutton\" value=\"Send Message\" />
</form>
</div>

');

}
?>


I have another question what should I add to display $name in form rather then 'Nobody' or 'Unknown.' Maybe something to do with headers?

Thanks!

Twey
02-25-2006, 06:57 PM
} else {
echo 'There was an error sending the mail, please go back and try again.';

} else {Two else statements in a row don't make sense. If you mean to close an if-else block before the second one, add another ending curly brace (}).
what should I add to display $name in form rather then 'Nobody' or 'Unknown.' Maybe something to do with headers?I don't understand: where would you like $name to appear? Where will you get $name from if the form hasn't been POSTed yet?

ralitza
02-25-2006, 09:27 PM
} else {
echo 'There was an error sending the mail, please go back and try again.';

} else {Two else statements in a row don't make sense. If you mean to close an if-else block before the second one, add another ending curly brace (}).I don't understand: where would you like $name to appear? Where will you get $name from if the form hasn't been POSTed yet?

I somewhat fixed it, but it still isn't sending.

Updated: http://www.iankovi.com/sponsicontact.php



<?php
$to = 'iankovi.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$message = wordwrap($message, 85);

if(isset($_POST['send']))
{

if (empty($name) || empty($email) || empty($subject) ||empty($message))
{

echo 'Please fill in and verify all fileds';

if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email']))
{

echo 'Please enter a valid email address.';

} else {
$send=mail('$to', '$email', '$subject');
}

if($send)
{
echo 'Mail sent successfully.';
}

} else {
echo 'There was an error, please go back and try again';
}

} else {

echo '

<div id="contactleft">
<h2>Contact customer service</h2>
<span class="elevensize">All fields should be filled in and verified</span>
<form action="" method="POST" class="margintenform">
Name: <br />
<input name="Name" type="text" class="inputlong" /> <br />
Email Address: <br />
<input name="Email" type="text" class="inputlong" /> <br />
Subject: <br />
<input name="Subject" type="text" class="inputlong" /> <br />
Detailed Message: <br />
<textarea name="Message" cols="5" rows="12" class="texarealong"></textarea>
<br />
<input name="send" type="submit" id="contantbutton" value="Send Message" />
<br />
</form>
</div>

'; }
?>

Twey
02-25-2006, 09:36 PM
Firstly, "iankovi.com" isn't a valid email address.
Secondly, you've encased the variables in single quotes, meaning that they won't be parsed; you're literally trying to send an email to $to.

ralitza
02-25-2006, 10:42 PM
Anymore suggestions?


<?php
error_reporting(E_STRICT);

$to = 'iankovi@msn.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$message = wordwrap($message, 85);

if(isset($_POST['send'])) {
if ((empty($name) || empty($email) || empty($subject) ||empty($message)) || (preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email']))) {
echo 'Please fill in and verify all fileds';
} else {
if(mail($to , $email, $subject, $message)) {
echo 'Mail sent successfully.';
} else {
echo 'There was an error, please go back and try again';
}
}
} else {
echo '

<div id="contactleft">
<h2>Contact customer service</h2>
<span class="elevensize">All fields should be filled in and verified</span>
<form action="" method="POST" class="margintenform">
Name: <br />
<input name="Name" type="text" class="inputlong" /> <br />
Email Address: <br />
<input name="Email" type="text" class="inputlong" /> <br />
Subject: <br />
<select name="select" class="selectinput">
<option selected="selected">&lt;Select&gt;</option>
<option>Company</option>
<option>Getting Started</option>
<option>Logging In</option>
</select>
<br />
Detailed Message: <br />
<textarea name="Message" cols="5" rows="12" class="texarealong"></textarea>
<br />
<input name="send" type="submit" id="contantbutton" value="Send Message" />
<br />
</form>
</div>

'; }
?>


Thank you for all your help!

Twey
02-25-2006, 10:58 PM
You want to negate the return value of that preg_match() call with a NOT operator:
(!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $_POST['email']))Also, the recommended line length for an email is 65, not 85 as you've used above.

ralitza
02-25-2006, 11:04 PM
Thank you, that and getting rid of the caps in the input names fixed the problem.

Edit; For some reason I am still not receving the emails?

Twey
02-25-2006, 11:15 PM
Try printing out all the variables before calling mail() to see what they all contain. If they all look right, the only other thing I can think of is that the SMTP server you're using isn't working properly, or possibly that your email account is junking the email. This has been known to happen with MSN/HoTMaiL accounts.