imagekrazy
asked on
my php script of my email form is giving me an error
Part of my php script in my email form is throwing out an error and i can't figure it out
Parse error: syntax error, unexpected T_STRING in /home/content/64/11583764/ html/summe r/test2/co ntact.php on line 25
I am attaching my file
contact.php
Parse error: syntax error, unexpected T_STRING in /home/content/64/11583764/
I am attaching my file
contact.php
ASKER
Hi, i can't understand why it stating Parse error
<?php
if(array_key_exists('send' ,$_POST)){
$to = 'circleimage@gmail.com';
$subject = 'Feedback from aummer rain wellness page';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
//limit line length to 70 characters
$message = "wordwrap($message,70);
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE HTML>
<head>
<title>Untitled Document</title>
<link href="contactStyle.css" rel="stylesheet" type="text/css" media="screen">
</head>
<?php
if(array_key_exists('send'
$to = 'circleimage@gmail.com';
$subject = 'Feedback from aummer rain wellness page';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
//limit line length to 70 characters
$message = "wordwrap($message,70);
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE HTML>
<head>
<title>Untitled Document</title>
<link href="contactStyle.css" rel="stylesheet" type="text/css" media="screen">
</head>
Please use the CODE SNIPPET feature! You can find this by clicking "Code" in the gray bar above the "Post a Comment" area. The line numbers and the exact code are important if we are to be able to help you.
ASKER
<?php
if(array_key_exists('send',$_POST)){
$to = 'circleimage@gmail.com';
$subject = 'Feedback from aummer rain wellness page';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
//limit line length to 70 characters
$message = "wordwrap($message,70);
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE HTML>
<head>
<title>Untitled Document</title>
<link href="contactStyle.css" rel="stylesheet" type="text/css" media="screen">
</head>
<body>
OK, thanks for that. And what is the error message and what is the line number?
Even when the error goes away, it will probably bounce because the proper headers are not being used. I can show you a demo, Ray has one too.
At Gmail, it will probably go in the spam folder until the recipient white-lists the sending domain.
I'm a little more concerned that we still do not have the correct script in front of us. For better or worse, computer programming is something that requires exacting precision and when I see "summer" spelled "aummer" it always makes me itch, wondering what else might be a little bit off.
I'm a little more concerned that we still do not have the correct script in front of us. For better or worse, computer programming is something that requires exacting precision and when I see "summer" spelled "aummer" it always makes me itch, wondering what else might be a little bit off.
ASKER
it saying syntax error at line 26 but i looked at that line and I attached a css file so what did I do wrong?
<?php
if(array_key_exists('send',$_POST)){
$to = '';
$subject = 'Feedback from aummer rain wellness page';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
//limit line length to 70 characters
$message = "wordwrap($message,70);
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE HTML>
<head>
<title>Untitled Document</title>
<link href="css/contactStyle.css" rel="stylesheet" type="text/css">
</head>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Lest your script come under attack and become an open-relay for spam, please learn about the principles of filtering and sanitizing the external variables.
http://php.net/manual/en/language.variables.external.php
http://php.net/manual/en/security.php
Here is a code snippet that will work correctly. Maybe you can start from here and build up your own application.
http://php.net/manual/en/language.variables.external.php
http://php.net/manual/en/security.php
Here is a code snippet that will work correctly. Maybe you can start from here and build up your own application.
<?php // RAY_form_to_email.php
error_reporting(E_ALL);
// SEND MAIL FROM A FORM
// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from = 'NoReply@Your.org';
$subj = 'Contact Form';
// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[] = 'You@Your.org';
$to[] = 'Her@Your.org';
$to[] = 'Him@Your.org';
$to[] = 'Ray.Paseur@Gmail.com';
// IF THE DATA HAS BEEN POSTED (AT LEAST SOMETHING IN THE EMAIL INPUT CONTROL)
if (!empty($_POST['e']))
{
// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
$safe_mail = clean_string($_POST['e']);
$safe_name = clean_string($_POST['n']);
$safe_fone = clean_string($_POST['t']);
$save_idea = clean_string($_POST['i']);
// CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
$content = NULL;
$content .= "You have a New Query From $safe_name" . PHP_EOL . PHP_EOL;
$content .= "Tel No: $safe_fone" . PHP_EOL;
$content .= "Email: $safe_mail" . PHP_EOL;
// SEND MAIL TO EACH RECIPIENT
foreach ($to as $recipient)
{
if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
{
echo PHP_EOL . "<br/>MAIL FAILED FOR $recipient";
}
else
{
echo PHP_EOL . "<br/>MAIL WORKED FOR $recipient";
}
}
// PRODUCE THE THANK-YOU PAGE
echo '<p>THANK YOU</p>' . PHP_EOL;
die('TASK COMPLETE');
}
// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="e" />
<br/>Phone: <input name="t" />
<br/>Name: <input name="n" />
<br/>Ideas? <textarea name="i"></textarea>
<br/><input type="submit" />
</form>
ENDFORM;
echo $form;
// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
// IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
$str = stripslashes($str);
// REMOVE EXCESS WHITESPACE
$rgx
= '#' // REGEX DELIMITER
. '\s' // MATCH THE WHITESPACE CHARACTER(S)
. '\s+' // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
. '#' // REGEX DELIMITER
;
$str = preg_replace($rgx, ' ', $str);
// REMOVE UNWANTED CHARACTERS
$rgx
= '#' // REGEX DELIMITER
. '[' // START OF A CHARACTER CLASS
. '^' // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
. 'A-Z0-9' // KEEP LETTERS AND NUMBERS
. '"' // KEEP DOUBLE QUOTES
. "'" // KEEP SINGLE QUOTES
. '@&+:?_.,/\-' // KEEP SOME SPECIAL CHARACTERS (ESCAPED HYPHEN)
. ' ' // KEEP BLANKS
. ']' // END OF THE CHARACTER CLASS
. '#' // REGEX DELIMITER
. 'i' // CASE-INSENSITIVE
;
$str = preg_replace($rgx, NULL, $str);
// REMOVE EXCESSIVE INPUT
$str = substr($str, 0, 255);
return trim($str);
}
HTH, ~Ray
ASKER
Wow, thank you very much, it works. and thank you for that example!
Thanks for the points! Good luck with the project, ~Ray
Open in new window
In the instant case, line 25 contains this:
<link href="contactStyle.css" rel="stylesheet" type="text/css" media="screen">
and that is not a PHP Parse Error. Please reduce the problem to the SSCCE and use the code snippet to show us what is still giving you trouble.