0

I feel a bit of a fraud to burden you with a same ol question about WSOD and a mystery Unexpected T_String in line 1, but try as I might I cannot work this out. I'm very new... this is my first use of PHP in about 5 years and back then it realy was my first attempt which, happily worked.

I'm creating a simple website which will have a Contact Us form... its going to ask in the HTML div main as follows:

<div id="wrap">
 <!.. various code that works just fine >
    <div id="main">
    <form action="mail.php" method="POST">
    <p>Name</p> <input type="text" name="name">
    <p>Email Address</p> <input type="text" name="email">
    <p>Message</p> <textarea name="message" rows="6" cols="25"> </textarea>
    <br />
    <input type="submit" value="Send"><input type="reset" value="Clear">   
    </form>

    </div> <!.. end of main>
<!.. some more code that also works fine>
</div> <!..end of wrap>   

Within the file called main.php I have written (well, copied from a website):

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
   <title>Contact Us PHP</title>
</head>
<body>


  <?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  $formcontent = "From: $name \n Message: $message";
  $recipient = "my.name@mybusiness.co.uk";
  $subject = "Contact Form";
  $mailheader = "From: $email \r\n";
  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  echo "Thank You for your message " . " - " .   
  "<a href='www.mybusinessname.co.uk/index.html'> Return Home </a>";
  ?>
  </body>
  </html>

I have loaded this to my hosted server and when I press my Submit Button the WSOD appears showing the address http://www.mybusinessname.co.uk .... /main.php

I have spent days reading up about various possible solutions that lose me quite quickly, but honestly I think i have done something basic that has a really simple solution, and someone much cleverer than me will be able to identify this pretty quickly.

Gray
  • 7,050
  • 2
  • 29
  • 52
Mike T
  • 1
  • Tip: Syntax highlighting is your friend – Izkata Feb 27 '13 at 20:00
  • 1
    What is the full exact error message? – yunzen Feb 27 '13 at 20:00
  • Also, what is `mail.php`? – Izkata Feb 27 '13 at 20:01
  • What program are you using to code your pages? Try a plain text editor to remove any characters you might not be seeing from your copy/paste. – j08691 Feb 27 '13 at 20:04
  • Are you able to use the shell on your hosting server? Did you try just running `php ./myscript.php` - That will generally tell you where you went wrong in these cases. – Tim Post Feb 27 '13 at 20:05
  • Your code works fine on my local server. are u sure you given code above from /home3/business40/public_html/interactive/mail.php – Parag Feb 27 '13 at 20:08
  • mail.php is the name of the php file and this is written out in the second part of my post. j08691 I used Komodo Edit 7.1.3 to code the site and php files. I'll try the shell solution, thanks Tim; and Parag that is not the real address - my site is in the same format but not as shown in that code. – Mike T Feb 27 '13 at 20:33
  • I need to warn you that your mail.php code is vulnerable to being hacked via mail header injection. The site you copied it from is clearly not a good resource. You may want to consider using a better mailer solution than this. – Spudley Oct 17 '13 at 13:04

1 Answers1

1

What is a single quote on line 1 for?

'<div id="wrap">

Are you echoing out the whole thing? If yes than please don't do that, instead do it like this

?>
<!--HTML Goes Here-->
<?php

As I don't see anything wrong in the code except this ' quote on line 1. Cuz either you've shared incomplete or irrelevant code

Generally this error is occured when there's unescaped quotes

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • the single quote is a typo in transcribing into this forum, not part of the code. I'm not sure what the second part of your question meant – Mike T Feb 27 '13 at 20:02
  • PHP Parse error: syntax error, unexpected T_STRING in /home3/business40/public_html/interactive/mail.php on line 1 – Mike T Feb 27 '13 at 20:06
  • @MikeT Is there any PHP on line 1? Or probably you are using html directly inside PHP tags – Mr. Alien Feb 27 '13 at 20:07
  • you'll need to post the code in mail.php, the error is likely telling you that there's either a single or double quote that doesn't belong on line 1 of mail.php – eric_spittle Feb 27 '13 at 20:09
  • @eric_spittle Yup, am sure it's the unescaped quotes issue here – Mr. Alien Feb 27 '13 at 20:09
  • Ok, thanks but excuse my ignorance - what is an unescaped quote? – Mike T Feb 27 '13 at 20:12
  • When you've something like this `echo 'Hello O\'Brein'` so using a trailing back slash you escape the single quote – Mr. Alien Feb 27 '13 at 20:13
  • @MikeT Ya that's what the funny part is, It's just HTML on line 1 – Mr. Alien Feb 27 '13 at 20:36
  • Ok just to be clear about what I have posted. The first chunk of code is an extract from my 'ContactUs.html' pure html file which calls the 'main.php' PHP file. The second chunk of code is the contents of main.php. I'm saying that because as far as I can see, its not just HTML on line 1 of the second chunk of code. Line 1 is – Mike T Feb 27 '13 at 20:48
  • OK Problem solved. I cut and pasted the code out of the original mail.php file and placed it in a file called contact.php, changed my ContactUs.html file accordingly and it worked. Maybe there were hidden characters in my original, much edited file, or maybe calling something 'mail.php' was not too clever since mail is a php command. Whatever, problem is solved. Thanks for your help everyone! – Mike T Feb 27 '13 at 21:02
  • @MikeT glad to know you are through ;) – Mr. Alien Feb 27 '13 at 21:15