Hi there all, I am brand new to php (3 days under my belt). I am trying to modify a webmail.php script that came on this cd that I got with the learning php book. I am having difficulty getting the new fields I added to work. I am getting a T_String error on line 33, But I can't seem to find any errors/dont know what kind of erroroneous code bit to fix. Please help me. I have pasted my code below. I have great faith that this community will be able to assist me.

send.php code is below the line
---------------------------------------------------------------------------------------------------


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Revisit-After" content="5 Days">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Thank you for adding this customer</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" alink="#0000FF" vlink="#0000FF">
<h1>Thank you for adding this customer</h1>


<?php
$to = "matt@ag0.net"; // change to your email address
$firstname = $_POST;
$lastname = $_POST;
$email = $_POST;
$homephone = $_POST;
$workphone = $_POST;
$address = $_POST;
$city = $_POST;
$state = $_POST;
$zip = $POST;
$directions = $_POST;
$msg = $_POST;
$d = date('l dS \of F Y h:i:s A');
$sub = "CCI $firstname $lastname";
$headers = "From: $firstname $lastname <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes .= "First Name: ".$firstname."\n;
$mes .= "Last Name: ".$lastname."\n;
$mes .= "e-mail: ".$email."\n;
$mes .= "Home Phone: ".$homephone."\n;
$mes .= "Work Phone: ".$workphone."\n;
$mes .= "Address: ".$address."\n;
$mes .= "City: ".$city."\n;
$mes .= "State: ".$state."\n;
$mes .= "Zip: ".$zip."\n;
$mes .= "Customer Directions: ".$directions."\n;
$mes .= "Additional Messages: ".$msg."\n;
$mes .= 'Date & Time Entered: '.$d;

if (empty($firstname) || empty($email) || empty($subject) || empty($msg))
{
echo " <h3>Sorry all fields are required.</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h3>Sorry the email address you entered looks like it's invalid.</h3>";
}
else
{
mail($to, $sub, $mes, $headers);
print " <h3><center>Thank you ".$firstname." for contacting us.</center></h3>";
print " <h3><center>We will get back to you as soon as possible</center></h3>";

}
?>

<!-- your html -->

</body>
</html>

Recommended Answers

All 4 Replies

Member Avatar for langsor

Aaak, use the CODE tags for your script code!

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Revisit-After" content="5 Days">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Thank you for adding this customer</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" alink="#0000FF" vlink="#0000FF">
  <h1>Thank you for adding this customer</h1>

<?php
$to = "matt@ag0.net"; // change to your email address
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$homephone = $_POST['homephone'];
$workphone = $_POST['workphone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $POST['zip'];
$directions = $_POST['directions'];
$msg = $_POST['msg'];
$d = date('l dS \of F Y h:i:s A');
$sub = "CCI $firstname $lastname";
$headers = "From: $firstname $lastname <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes .= "First Name: ".$firstname."\n";
$mes .= "Last Name: ".$lastname."\n";
$mes .= "e-mail: ".$email."\n";
$mes .= "Home Phone: ".$homephone."\n";
$mes .= "Work Phone: ".$workphone."\n";
$mes .= "Address: ".$address."\n";
$mes .= "City: ".$city."\n";
$mes .= "State: ".$state."\n";
$mes .= "Zip: ".$zip."\n";
$mes .= "Customer Directions: ".$directions."\n";
$mes .= "Additional Messages: ".$msg."\n";
$mes .= 'Date & Time Entered: '.$d;

if ( empty($firstname) || empty($email) || empty($subject) || empty($msg) ) {
  echo "  <h3>Sorry all fields are required.</h3>";
} elseif ( !ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) ) {
  print "  <h3>Sorry the email address you entered looks like it's invalid.</h3>";
} else {
 mail( $to, $sub, $mes, $headers );
  print "  <h3><center>Thank you ".$firstname." for contacting us.</center></h3>";
  print "  <h3><center>We will get back to you as soon as possible</center></h3>";
}
?>
<!-- your html -->
</body>
</html>

All of these need to have a closing double-quote before the closing semi-colon
corrected above

$mes .= "First Name: ".$firstname."\n;
$mes .= "Last Name: ".$lastname."\n;
$mes .= "e-mail: ".$email."\n;
$mes .= "Home Phone: ".$homephone."\n;
$mes .= "Work Phone: ".$workphone."\n;
$mes .= "Address: ".$address."\n;
$mes .= "City: ".$city."\n;
$mes .= "State: ".$state."\n;
$mes .= "Zip: ".$zip."\n;
$mes .= "Customer Directions: ".$directions."\n;
$mes .= "Additional Messages: ".$msg."\n;

T_String errors are some problem with non-closed strings ... thus forgetting to end quote (') or double-quote (") a line of text. Also, single and double quotes must match, they are not interchangeable.

Get a good code editor with line-numbers and syntax highlighting and save yourself hours-days-weeks-years or pain and frustration ...

Keep at it, and good luck!

Member Avatar for langsor

Last word ...

the "\n" is a newline-linebreak in scripting-lingo. It is like a soft carriage return.
In PHP the newline character \n must be in double-quotes to not be displayed literally, thus to be interpreted as an actual new line.

Javascript will display it in single or double-quotes.

Cheers.

thank you so much for your help.

Member Avatar for langsor

thank you so much for your help.

You're welcome, glad to be able to help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.