php error

This is a discussion on "php error" within the PHP Forum section. This forum, and the thread "php error are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 20th, 2007, 18:00
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
php error

Getting an error, could someone check my code please

main page that you input data
Code: Select all
<head>
<title>Email Form</title>
</head>

<body>
<Form action="sendmail.php" method post
<p><strong>Name:</strong><br /> <input type="text" size="25" name="name" /></p>
<p><strong>E-mail Address:</strong><br />
<input type="text" size="25" name="email" /></p>
<p><strong>Message:</strong><br />
<textarea name="message" cols="30" rows="5"></textarea></p>
<p><input type="submit" value="send" /></p>
</Form>
</body>
</html>
and then the action page

Code: Select all
<head>
<title>Sending Mail</title>
</head>

<body>
<?php
echo "<p>Thank you, <b>"$_POST["name"]."</b>, for your message!</p>";
echo "<p>Your e-mail address is: <b>".$_POST["email"]."</b>.</p>";
echo "<p>Your message was: <br>"";
//start building the mail string
$msg = "Name":        ".$_POST["name"]."\n";
$msg .= "E-Mail:    ".$_POST["email"]."\n";
$msg .= "Message    ".$_POST["message"]."\n";
//set up the mail
$recipient = "name@domainname.com";
Ssubject = "Message from website";
$mailheaders = "From: My Website <name@domainname.com> \n";
$mailheaders .= "Reply-To: ".$_POST["email"];
//send the email
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>
thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 20th, 2007, 18:02
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Here it is live online

http://www.lightex.co.uk/testfolder/feedback.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 20th, 2007, 18:15
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

The HTML at the start of the form line should be:
HTML: Select all
<form method = "post" action="sendmail.php">
In your PHP code, you say "Your message was:" but then never echo() $msg, so the message won't be displayed.
Also, remember to filter HTML characters from your input before putting the code live.
Use htmlspecialchars().

This code might pose a problem:
PHP: Select all

echo "<p>Your message was: <br>""; 

Due to the two quotes at the end, you would be terminating the string to echo then opening a new one without closing.
Just remove one to fix the problem.
Also, in the first line of the PHP you missed out a concatenation "dot", and you had an extra quote after "Name", and a few other bits and bobs.


So some code for the PHP part might be:
PHP: Select all

<head>
<title>Sending Mail</title>
</head>

<body>
<?php
echo "<p>Thank you, <b>" htmlspecialchars($_POST['name']) . "</b>, for your message!</p>";
echo 
"<p>Your e-mail address is: <b>" htmlspecialchars($_POST['email']) . "</b>.</p>";
echo 
"<p>Your message was: <br>";
//start building the mail string
$msg "Name:        " $_POST['name'] . "\n";
$msg .= "E-Mail:    " $_POST['email'] . "\n";
$msg .= "Message    " $_POST['message'] . "\n";
//set up the mail
$message $_POST['message'];
echo (
htmlspecialchars($message));
$recipient "name@domainname.com";
$subject "Message from website";
$mailheaders "From: My Website <name@domainname.com> \n";
$mailheaders .= "Reply-To: " $_POST['email'];
//send the email
mail($recipient$subject$msg$mailheaders);
?>
</body>
</html>

But apart from that, sendmail.php gives me a 404 error.
Are you sure it has been uploaded to your server?

Last edited by balaclave; Jul 20th, 2007 at 19:56.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 20th, 2007, 18:53
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Sorry forgot to upload that part, but still getting nothing

http://www.lightex.co.uk/testfolder/sendmail.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 20th, 2007, 19:22
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Can you post exactly what code is in sendmail.php?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 20th, 2007, 19:27
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Quote:
<?php
echo "<p>Thank you, <b>" . htmlspecialchars($_POST["name"]) . "</b>, for your message!</p>";
echo "<p>Your e-mail address is: <b>" . htmlspecialchars($_POST["email"]) . "</b>.</p>";
echo "<p>Your message was: <br>";
//start building the mail string
$msg = "Name: " . $_POST["name"] . "\n";
$msg .= "E-Mail: " . $_POST["email"] . "\n";
$msg .= "Message " . $_POST["message"] . "\n";
//set up the mail
echo ("htmlspecialchars($msg)");
$recipient = "alex@acrikey.com";
Ssubject = "Message from website";
$mailheaders = "From: My Website <alex@acrikey.com> \n";
$mailheaders .= "Reply-To: " . $_POST["email"];
//send the email
mail($recipient, $subject, $msg, $mailheaders);
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 20th, 2007, 19:29
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

There are still some code errors. Try this:

HTML code:
Code: Select all
<head>
<title>Email Form</title>
</head>

<body>
<form action="sendmail.php" method="post">
<p><strong>Name:</strong><br /> <input type="text" size="25" name="name" /></p>
<p><strong>E-mail Address:</strong><br />
<input type="text" size="25" name="email" /></p>
<p><strong>Message:</strong><br />
<textarea name="message" cols="30" rows="5"></textarea></p>
<p><input type="submit" value="send" action="submit" /></p>
</form>
</body>
</html>
and PHP code:

PHP: Select all

<head>
<title>Sending Mail</title>
</head>

<body>
<?php
//start building the mail string
$msg "Name:        " $_POST["name"] . "\n";
$msg .= "E-Mail:    " $_POST["email"] . "\n";
$msg .= "Message    " $_POST["message"] . "\n";
// output to the user
echo("<p>Thank you, <b>" htmlspecialchars($_POST["name"]) . "</b>, for your message!</p>");
echo(
"<p>Your e-mail address is: <b>" htmlspecialchars($_POST["email"]) . "</b>.</p>");
echo(
"<p>Your message was: ".htmlspecialchars($msg)."<br>");
//set up the mail
$recipient "name@domainname.com";
$subject "Message from website";
$mailheaders "From: My Website <name@domainname.com> \n";
$mailheaders .= "Reply-To: " $_POST["email"];
//send the email
mail($recipient$subject$msg$mailheaders);
?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 20th, 2007, 19:57
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Thought I'd make another reply.
My PHP is now tested and working (quotation marks around htmlspecialchars() were causing php to output that as text, and an S had somehow sneaked in and replaced a $ symbol ).
At the moment, my original code and c010depunkk's will output $msg which is the email message - I think it would be better just to output $_POST['message'] at the place where it says "Your message was:".

This defintely works:
PHP: Select all

<head>
<title>Sending Mail</title>
</head>

<body>
<?php
echo "<p>Thank you, <b>" htmlspecialchars($_POST['name']) . "</b>, for your message!</p>";
echo 
"<p>Your e-mail address is: <b>" htmlspecialchars($_POST['email']) . "</b>.</p>";
echo 
"<p>Your message was: <br>";
//start building the mail string
$msg "Name:        " $_POST['name'] . "\n";
$msg .= "E-Mail:    " $_POST['email'] . "\n";
$msg .= "Message    " $_POST['message'] . "\n";
//set up the mail
$message $_POST['message'];
echo (
htmlspecialchars($message));
$recipient "name@domainname.com";
$subject "Message from website";
$mailheaders "From: My Website <name@domainname.com> \n";
$mailheaders .= "Reply-To: " $_POST['email'];
//send the email
mail($recipient$subject$msg$mailheaders);
?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jul 20th, 2007, 20:24
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

it's just sitting on sendmail.php, not doing anything
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jul 20th, 2007, 21:46
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Re-upload a working version and try again?
Does your host support PHP?
It works here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jul 20th, 2007, 23:08
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

thank you sorted, it's working fine thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jul 20th, 2007, 23:18
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Quote:
thank you sorted, it's working fine thank you
Great!
Is there anything else you would like to know to tweak your form, or are you happy with it now?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jul 20th, 2007, 23:27
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Hey balaclave where you learn all this php goodliness. I'm struggling with it all to be honest.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jul 21st, 2007, 00:27
Reputable Member
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Not that I can think of, but I'm bookmarking you, your very useful!!!!
Thanks again mate.
Still learning php so thought I was doing well till it did not work!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jul 21st, 2007, 18:05
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php error

Quote:
Hey balaclave where you learn all this php goodliness.
Nowhere really.
I've not had any tuition but I'm good at maths and problem solving which, I am certain, helps.
php.net is probably the most useful website (since it contains the php manual).
For everything else there's Google.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
php error

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Getting the &quot;Microsoft JET Database Engine error '80040e14'&quot; error. VegaLA Classic ASP 3 Jan 26th, 2008 00:12
Keep getting error message Microsoft VBScript runtime error '800a01a8' cpando1974 Classic ASP 2 Aug 7th, 2007 12:00
Error 500 - Internal server error JasonStanley PHP Forum 3 Apr 23rd, 2007 17:56


All times are GMT. The time now is 16:19.