Hey guys this is my first post of which I think will be many. Let me explain my situation, after a great fall semester at my internship my company asked me to stay on with them and work part time through the spring semester. At first my job was to do alot of static html work. But now we want to take the dive into MySQL and PHP, they will pay me to train myself so it isn't too bad. I ran over to the local B&N and purchased "Sams Teach Yourself: PHP, MySQL, and Apache", and i have been just going through the tutorials.

So now I'am up to the point where I need to make an HTML Form and then have it send through a PHP Mailing script here is what I have.

<html>
<head>
<title>Sending mail from the form in Listing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form actions="<?php $_SERVER["PHP_SELF"]; ?>" method="POST">
<p><strong>Name:</strong><br> <input type ="text" size ="25"
name="name" />
</p>
  <p><strong>Email:</strong><br>
     <input type ="text" size ="25"
name="email" />
</p>
  <p><strong>Subject:</strong><br>
     <input type ="text" size ="25"
name="subject" />
</p>
<p><strong> Message:</strong><br>
<textarea name="message" cols="30" rows="5"></textarea>
</p>
<p><input type="submit" value="send" />
</p>
</form>
<?php
echo "<p>Thank You, <b>".$_POST["name"]."<b/>, for your message!</p>";
echo "<p> Your email address is: <b>".$_POST["email"]."</b>.</p>";
echo "<p> Your message was:<br/>";
echo $_POST["message"]."</p>;
$msg = "Name: ".$_POST["name"]."\n"; //Line of Code that is a problem
$msg .= "Email: ".$_POST["email"]."\n";
$msg .= "Message: ".$_POST["message"]."\n";
$recipient = "xxxxx@gmail.com";
$subject = ".$_POST["subject"];
$mailheaders = "From: StormMagazine.com Test Website \n";
$mailheaders = "Reply-To: ".$_POST["email"];
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>

My first question is can I have the mailing script in the same code with the HTML form and use the <form actions="<?php $_SERVER["PHP_SELF"]; ?> to read itself?

When I do run the page it keeps coming back with this little error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /usr/home/stormmag/public_html/Steve/sendmail.php on line 30

I'm sorry for the long winded post. I read the forum rules and I believe this is the etiquette if not your help is greatly appreciated. Thanks guys

    <html> 
    <head> 
    <title>Sending mail from the form in Listing</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> 
    <body> 
    <form actions="<?php $_SERVER["PHP_SELF"]; ?>" method="POST"> <p><strong>Name:</strong><br> <input type ="text" size ="25" name="name" /> </p>  
    <p><strong>Email:</strong><br> <input type ="text" size ="25" name="email" /> </p>
    <p><strong>Subject:</strong><br> <input type ="text" size ="25" name="subject" /> </p> <p><strong> Message:</strong><br> <textarea name="message" cols="30" rows="5"></textarea> </p> <p><input type="submit" value="send" /> </p> </form> <?php echo "<p>Thank You, <b>".$_POST["name"]."<b/>, for your message!</p>"; echo "<p> Your email address is: <b>".$_POST["email"]."</b>.</p>"; echo "<p> Your message was:<br/>"; echo $_POST["message"]."</p>"; $msg = "Name: ".$_POST["name"]."\n"; //Line of Code that is a problem $msg .= "Email: ".$_POST["email"]."\n"; $msg .= "Message: ".$_POST["message"]."\n"; $recipient = "xxxxx@gmail.com"; $subject = ".$_POST["subject"]; $mailheaders = "From: StormMagazine.com Test Website \n"; $mailheaders = "Reply-To: ".$_POST["email"]; mail($recipient, $subject, $msg, $mailheaders); ?> </body> </html>

    Look at the colours

      I'm very new at coding. What do you mean by look at the colors.
      I understand the blue is HTML
      Yellow Forms
      But nothing else is really jumping out at me.

        you have variables on the left of the page. the

         tags assign variables one colour, functions another calour etc. your variables have two colours

          ive just been through your code in more detail and its a bit of a mess. instead of leaving you to fester on your own i will give you a few pointers.
          1. if you're using double quotes you dont need to concatenate as you can use variables and functions inside the quotes
          2. if you are using double quotes, using other double quotes inside of these ends the first and starts a second load. you can either alternate single and double quotes or escape the quotes with .

          so

          echo "<p>Thank You, <b>".$_POST["name"]."<b/>, for your message!</p>";

          can be written

          echo "<p>Thank You, <b>\"$_POST[\"name\"]\"<b/>, for your message!</p>";

          or

          echo "<p>Thank You, <b>'$_POST["name"]'<b/>, for your message!</p>";

          also, when i use functions inside double quotes i tend to encase them in curly braces. i cant remember why now but it works.

          echo "hello {$_POST['name']}";

          you have many problems here

            The error was in the line above the one you indicated: it had a " missing, so the string was not closed after the </p> as it should have been. PHP therefore considered the beginning of the nest line to be part of the same string up untill it encountered another ". This threw the syntax for that next line out and PHP threw an error for that line, hence your message.

            My comment was meant to teach you to look at the colour coding which really helps to spot these typos. If you compare my post of the code to yours you will see that I have corrected the error and the colouration changes in comparison to your post of the 'almost' identical code.

              Write a Reply...