Link to home
Start Free TrialLog in
Avatar of imagekrazy
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/summer/test2/contact.php on line 25

I am attaching my file
contact.php
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please use the code snippet feature to post code here at EE, thanks.

<?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>

<div id="header">
    <h1>Summer Rain Wellness</h1>
</div>
<div id="wrapper">
<?php include('includes/menu.inc.php'); ?>

    <div id="maincontent">
      <h2>Contact Us </h2>
      <?php
	  if ($_POST && #mailSent){
		  ?>
          <p class="warning">Sorry, there was a problem sending your message. Please try later.</p>
          <?php
	  }
	  elseif ($_POST && $mailSent) {
		  ?>
          <p><strong>Your message has been sent, thank you for your fed back</strong></p>
          <?php } ?>
      <p>Ut enim ad minim veniam, quis nostrud exercitation consectetur adipisicing elit. Velit esse cillum dolore ullamco laboris nisi in reprehenderit in voluptate. Mollit anim id est laborum. Sunt in culpa duis aute irure dolor excepteur sint occaecat.</p>
        <form id="feedback" method="post" action="">
            <p>
                <label for="name">Name:</label>
                <input name="name" id="name" type="text" class="formbox">
            </p>
            <p>
                <label for="email">Email:</label>
                <input name="email" id="email" type="text" class="formbox">
            </p>
            <p>
                <label for="comments">Comments:</label>
              <textarea name="comments" id="comments" cols="60" rows="8"></textarea>
            </p>
            <p>
                <input name="send" id="send" type="submit" value="Send message">
            </p>
        </form>
      
    </div>
    <?php include('includes/footer.inc.php'); ?>
</div>
</body>
</html>

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.
Avatar of imagekrazy
imagekrazy

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>
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.
<?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>

Open in new window

OK, thanks for that.  And what is the error message and what is the line number?
Avatar of Dave Baldwin
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.
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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

<?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);
}

Open in new window

HTH, ~Ray
Wow, thank you very much, it works. and thank you for that example!
Thanks for the points!  Good luck with the project, ~Ray