Jump to content

[SOLVED] Please help me - PHP Form Question


mantona

Recommended Posts

It's my first time creating a form so I've probably done everything wrong. I copied this process.php from a website but cannot get it to work as it comes up with parse error on line 12. Can someone help please.

 

*** COPY OF PROCESS.PHP BELOW ***

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

<?php

// this sets up your email headers, just change the email address
$headers = "From: "webmaster@stmagnusbayhotel.co.uk\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";

// this emails you the results of the form
mail( "Webmaster@stmagnusbayhotel.co.uk", "New Contact Message", print_r( $_POST, true),"$headers">

// this will redriect the user somewhere away from this page
header("location: http://www.stmagnusbayhotel.co.uk/thanks.html");

?>

</body>

</html>

 

Thank you

Link to comment
Share on other sites

Well for one, your php header won't work because you have HTML already at the top.

 

Second this line is wrong

 

mail( "Webmaster@stmagnusbayhotel.co.uk", "New Contact Message", print_r( $_POST, true),"$headers">

 

You have a > at the end instead of a ) and no semi colon.

Link to comment
Share on other sites

I have changed the items you mentioned.  There is no html and now there is also ); at the end of the line you spoke about

 

Unfortunately the php still does not work and gives an error:

Parse error: parse error, unexpected T_STRING in /homepages/46/d134203705/htdocs/stmagnus/process.php on line 4

 

What are inescaped strings?

 

Here is my code again now:

<?php

// this sets up your email headers, just change the email address
$headers = "From: "webmaster@stmagnusbayhotel.co.uk\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";

// this emails you the results of the form
mail( "Webmaster@stmagnusbayhotel.co.uk", "New Contact Message", print_r( $_POST, true),"$headers");

// this will redriect the user somewhere away from this page
header("location: http://www.stmagnusbayhotel.co.uk/thanks.html");

?>

 

Thank you for your help

Link to comment
Share on other sites

Try this:

 

$headers = "From: webmaster@stmagnusbayhotel.co.uk\r\n" .
"X-Mailer: PHP" . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";

// this emails you the results of the form
mail( "Webmaster@stmagnusbayhotel.co.uk", "New Contact Message", print_r( $_POST, true),"$headers");

// this will redriect the user somewhere away from this page
header("location: http://www.stmagnusbayhotel.co.uk/thanks.html");

?>

 

 

Link to comment
Share on other sites

Thank you very much for your help.

 

The form work until it is meant to redirect to the thanks.html page then it comes up with:


on the screen and thats it.  Can this be fixed easily?

 

Also just as a curiosity, does every email get sent via my business email address?  Is this open from abuse by spammers?  e.g. where it says from: How does it work?

 

Thank you again, your help appreciated.

Link to comment
Share on other sites

The redirect should be:

 

header("Location: http://www.stmagnusbayhotel.co.uk/thanks.html");

 

The email from address will be what you specified in the headers, and is sent by the server.  It will only send from your business email address if that's what you specify in the From Address.

Link to comment
Share on other sites

Still not working.  This is how I've got it typed up.  I do not have html headers in the process.php file.  I'm not really sure what you mean.:

 

 

<?php

$headers = "From: webmaster@stmagnusbayhotel.co.uk\r\n" .
"X-Mailer: PHP" . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";

// this emails you the results of the form
mail( "Webmaster@stmagnusbayhotel.co.uk", "New Contact Message", print_r( $_POST, true),"$headers");

// this will redriect the user somewhere away from this page
header("Location: http://www.stmagnusbayhotel.co.uk/thanks.html");

?>

 

I've tried altering a few things but does not help.  It still just re-directs to page titled: http://www.stmagnusbayhotel.co.uk/process.php

 

with


onscreen

 

Thank you

Link to comment
Share on other sites

Remove the html from the top of the file, the headers are set there.

 

Remove:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

keep the php code

 

Remove

 

</body>
</html>

 

The only thing in the processing page should be the php code.

Link to comment
Share on other sites

Thank you very much.  This form now works.

 

Can I ask your opinion please?  Do you think that it is a good idea to send from my email address like that?  Does it matter?  Are there better options?

 

Thank you once again for helping me sort out the form issue

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.