Simplest of web forms not working, lots of hints

by THK
19 replies
I am getting an error like- "[15-Apr-2011 02:29:33] PHP Parse error: syntax error, unexpected T_ECHO in... (bla bla bla)... on line 13". Line 13 is the mail() command so the problem probably is with $msg, which is the line before.

My research shows that the problem is I am missing a (") or "}" or something similar. My php is not finding it, instead seeing the end of php (?>).

Triple checked everything, can't see anything missing. It is the simplest of forms you will ever see, might take you only a second to figure out what I can't. I would really apprecite if you take a glance at the codes and point me to a solution.

Here are the codes-

Web Form:



Code:
<form action="contact.php" method="post" id="contactform">

<ol>
<li><label for="firstname">Name</label><br/>
<input name="firstname" type="text" /></li><br/>
<li><label for="email">Email</label><br/>
<input name="email" type="text" /></li><br/>
<li><label for="comment">Comment</label><br/>
<textarea row="6" cols="50" name="comment"></textarea></li><br/>
<input value="send" type="submit" />
</ol>
</form>

PHP codes:


Code:
<html>
<head>
<title>this was a try</title>
</head>
<body>


<?php
$name = $_POST['firstname'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$to = 'myemail@yahoo.com';
$subject = 'test';
$msg = "$name sent you a message from $email and said $comment";

mail($to, $subject, $msg, 'From:' . $email);

echo 'Thanks for you comment.<br/>';
echo 'Your message has been sent from' . $email . '<br/>';
echo 'We will get back to you with in 48 hours or less.';

?>

</body>
</html>

The only difference is that I replaced "myemail@yahoo.com" with a real email adress


You can also check out the whole issue here- Web Design Questions: Simple web form not working

Thanks a lot guys for taking a look. Looking forward to your comments or thoughts on this.
#error #form #php #web forms
  • Profile picture of the author omerbsh
    i checked the code and its just fine...
    can you give me the full error?
    {{ DiscussionBoard.errors[3719077].message }}
  • Profile picture of the author THK
    Thanks Omerbesh for taking a look. The whole error looked something like this-

    [15-Apr-2011 02:29:33] Parse error: syntax error, unexpected T_ECHO in /usr/home/Userid/www/htdocs/contact.php5 on line 13

    I haven't kept the real text, but the deleted part (where I said bla bla bla etc.) was mainly pointing to my php file. when I ran the test for the first time, it created an error log (a different file) that had that line of text showing the error.

    Since then I tweaked the php file and tried again, no error log but result is the same.

    Thanks again

    Tanvir
    {{ DiscussionBoard.errors[3719998].message }}
  • Profile picture of the author Casey Moore
    Try this:
    $headers = "From:" . $email;
    mail( $to, $subject, $message, $headers);

    Heres why I didn't put it in code tags, appears like this:
    Code:
     = "From:" . ;
     mail( , , , );
    {{ DiscussionBoard.errors[3720082].message }}
    • Profile picture of the author omerbsh
      try to find the mail func in php website.
      try Case Moorey code and tell us if its works...
      {{ DiscussionBoard.errors[3720436].message }}
      • Profile picture of the author THK
        Originally Posted by omerbsh View Post

        try to find the mail func in php website.
        try Case Moorey code and tell us if its works...
        Thanks again omerbsh but as I am feeling dumber by the second, I have to ask, what is Case Moorey code?
        {{ DiscussionBoard.errors[3720603].message }}
  • Profile picture of the author THK
    Thanks for your input Casey. Nothing changes. Tried some other tweaks as well, nothing. At this point it seems like I am doing something insanely stupid that nobody is thinking about(including myself) or the problem is on the server side. Server side problem is very unlikely since I am receiving the message, just not the way I want. Also talked to the gator support, just to be sure.

    Only two things I can think of from this point on is post an ad on a freelance site or hire a real programmer(!), which seems like a overkill for such a small job. With basic coding knowledge and over half a dozen opinion on this code, I am kind of clueless now. Who knew in this day and age it would be so difficult to run a simple web form...lolz.

    I think I have to kill my frustrations before I can work on this any further. In the mean time, if any of you warriors have the time and patience to take look at this mess(!) and give me some pointers, I would appreciate that a lot.

    Tanvir
    {{ DiscussionBoard.errors[3720586].message }}
  • Profile picture of the author Casey Moore
    Hmm I'll throw this out there maybe it'll work:

    $msg = $name . "sent you a message from " . $email . " and said " . $comment;

    Once again couldn't use the code tags
    {{ DiscussionBoard.errors[3722949].message }}
  • Profile picture of the author THK
    Thanks Casey, I actually tried that, but not with ("). I did it with ('). Not sure it will make any difference, but I'll try that as well.

    Tanvir
    {{ DiscussionBoard.errors[3723130].message }}
    • Profile picture of the author Fred_Acker
      Tanvir it looks like you have " where there should be ' on this line:

      = " sent you a message from and said ";
      Try this:

      = ' sent you a message from and said ';
      Signature

      Right Now. What a wonderful time to start!

      {{ DiscussionBoard.errors[3723215].message }}
  • Profile picture of the author THK
    Thanks Fred for the idea. Of course if I put the whole string in a single quote it won't work (it will not recognize the variables), so I tried the way Casey showed above, with single and double quotes. Same results.

    Interestingly it seems like people are not even interested to get paid to sort it out. Half of the Fiverr community who offered this type of gig got a pm from me and I got only two responses...lol. I have to find a way to give them access to my server without compromising security. Maybe I should try to find out how to do that.

    I really appreciate all the responses guys. Many thanks for taking a look.

    Back to work.
    {{ DiscussionBoard.errors[3723599].message }}
  • Profile picture of the author Evan-M
    instead of

    mail($to, $subject, $msg, 'From:' . $email);

    try

    $from = "From: $email <$email>";
    mail($my_email,$subject,$message,$from);
    Signature

    Evan-M

    Easily The Worlds Best Wordpress Popup plugin

    Visit Website Design Firm For All Your Wordpress Coding Needs

    {{ DiscussionBoard.errors[3723895].message }}
  • Profile picture of the author THK
    Thanks Evan. Tried, didn't work. I am sure it is something to do with me, missing something very obvious. Looking at those files now making me sick. I don't remember when was the last time I worked on something so stupid for so long and got no result.

    Off to the freelance sites to find some help (my brain is fried), I need to know what the #@%& is up with that little bugger.

    But I honestly appreciate every single bit of help I got from all of you guys. Big thanks to all of you.

    Tanvir
    {{ DiscussionBoard.errors[3724885].message }}
  • Profile picture of the author SteveJohnson
    Doubt if you really need to give server access to anyone. Zip the offending file, PM it to me. Don't make any changes. Also copy/paste the exact error message into PM.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[3724905].message }}
    • Profile picture of the author THK
      Originally Posted by SteveJohnson View Post

      Doubt if you really need to give server access to anyone. Zip the offending file, PM it to me. Don't make any changes. Also copy/paste the exact error message into PM.
      Thanks Steve for your offer to help. Don't know how to send you attachments, but sent you a pm.

      @vgulavni

      [15-Apr-2011 02:29:33] Parse error: syntax error, unexpected T_ECHO in /usr/home/Userid/www/htdocs/contact.php5 on line 13

      This is what it was. For some reason(don't ask why) I deleted this part -/usr/home/Userid/www/htdocs/contact.php5 later. But I remember it was pointing to the php files in that format. I thought if the problem is not fixed, the error log will show up again. It didn't.

      Thanks guys.

      Tanvir
      {{ DiscussionBoard.errors[3725439].message }}
  • Profile picture of the author SmartWeb
    Hey Tanvir,

    You can try the following things, see if this helps,

    1st > modify the line
    mail($to, $subject, $msg, 'From:' . $email);

    to this
    mail($to, $subject, $msg);

    see if this works, then your last parameter is causing issues.

    2nd> try modifying the last para meter as follows,

    mail($to, $subject, $msg, 'From:' . $email. '\r\n');
    or
    mail($to, $subject, $msg, 'From: ' . $email);
    or
    mail($to, $subject, $msg, 'From: test@test.com');

    Try these things and let us know.
    Please post the exact error you getting..
    {{ DiscussionBoard.errors[3725668].message }}
  • Profile picture of the author oknoorap
    Hi, try jotform.com its simple, and awesome.
    {{ DiscussionBoard.errors[3725703].message }}
  • Profile picture of the author THK
    Little Update:As I have created the practice environment and running some more tests, I got those error logs again. Some of you were asking for the exact error message, so here it is-

    [18-Apr-2011 02:17:37] PHP Parse error: syntax error, unexpected T_VARIABLE in /home/username/public_html/test/contact.php on line 18
    [18-Apr-2011 02:22:45] PHP Parse error: syntax error, unexpected T_VARIABLE in /home/username/public_html/test/contact.php on line 18

    That is the exact message copied from that log file, just username should be replace by the real username. Nothing else has changed.

    Don't know if that helps, but I thought I post it here.

    Smartweb, thanks for your detailed suggestions. Maybe I haven't tried that yet, or did I. Anyway, I'll try that again. Will let you guys know the result.

    Thanks all.

    Tanvir
    {{ DiscussionBoard.errors[3725808].message }}
  • Profile picture of the author Evan-M
    can you send me the 2 files in question, want to try the form on my server and see it work, if i come up with anything ill post the result and problem.

    you can send them on skype or on here
    Signature

    Evan-M

    Easily The Worlds Best Wordpress Popup plugin

    Visit Website Design Firm For All Your Wordpress Coding Needs

    {{ DiscussionBoard.errors[3726972].message }}
    • Profile picture of the author lordspace
      1 suggestion: use Zend_Mail or phpmailer to send your emails rather than the default mail function. Reason: the parameters are checked

      a spammer could inject some headers (e.g. additional: Cc:, Bcc: etc fields) and your site could become a spammer's weapon.
      Signature

      Are you using WordPress? Have you tried qSandbox yet?

      {{ DiscussionBoard.errors[3796583].message }}

Trending Topics