Question

Hello there,

i am hoping someone out there can tell me where im going wrong.

I have a website where i am trying to get potential customers to fill out 5 simple text boxes on a HTML page and for the text entries to be processed by PHP code to send an e-mail to my e-mail inbox.

I have put the following code together and after spending hours to get over Parse and syntax errors. It finally sends me an e-mail.

The problem being that none of the text entered onto the HTML form appears in the e-mail at the end.

Can you help?

Heres the code

Running 2 files - one for the PHP and one for the HTML page.


<html>
<form action="send.php" method="post">
Name:<br> <input type="text" name"names"><br>
Email:<br /><input type="text" name"email"/><br />
Date From: <br /><input type"text" name"from"/> <br />
Date to: <br /><input type"text" name "dateto"/><br />
Details: <br /><textarea name"details"></textarea>
<input type="submit" name="Submit" value"send" />
</form>

</html>
[/CODE]

and here is the 2nd file with all the php code

- i believe the probelm lies when we get to the $body part:

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>send.php</title>
</head>
<?php
$names = $_post['names'];
$email = $_post['email'];
$from = $_post['from'];
$dateto = $_post['dateto'];
$details = $_post['details'];
$to = "MY EMAIL ADDRESS HERE";
$subject = "Customer Enquiry";
$body = 'Name:'.$names .'Email:'.$email .'From:'.$from .'To:'.$dateto .'Details:'.$details;
mail ($to,$subject,$body);
echo "Thank you for your enquiry. Your Message has been Sent. You will be contacted as soon as is possible. <a href='http://www.stleonard.info/default.html'>Click
?>
<body>
</body>
</html>
[/CODE]

Thanks !

11 answers to this question

Recommended Posts

  • 0

You've forgot "=" for some name and value attributes, e.g.:

Date to: <br /><input type"text" name="dateto"/><br /
^
here _/
[/CODE]

Therefore $_POST didn't even contain the assumed entries.

Prevent this by temporarily echoing variables to see if they contain expected values, e.g., [font=Courier New]print_r($_POST);[/font] or [font=Courier New]echo $body;[/font]

Or you can use HTML validator which amidst of being confused by all other mischiefs gives you:

25668aq.png

  • 0

Okay,

I have spent a while now but have managed to remvoe all the errors from the code.

The only problem now, is that it doesnt do what it is suppost to do.

Getting Data entered by a user from a webpage in HTML >> sent to PHP >> sent to my e-mail inbox.

I get the emails but the data isnt in the message also using the code


echo $body
[/CODE]

produces nothing but the fields i typed.

I am all out of ideas now...

Any suggestions?

heres the amended code:

THE HTML FILE:

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>
<body>
<form name="input" action="send.php" method="post"/>
Name:<input type="text" name="names"/>
Email:<input type="text" name="email"/>
Date From:<input type="text" name="from"/>
Date to:<input type="text" name="dateto"/>
Details:<textarea name="details" rows="8" cols="30"></textarea>
<input type="submit" name="Submit" value="Send"/>
</body>
</html>
[/CODE]

Heres the PHP File doing the mailing work:

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>send.php</title>
</head>
<?php
$names = $_post['names'];
$email = $_post['email'];
$from = $_post['from'];
$dateto = $_post['dateto'];
$details = $_post['details'];
$to = "MYEMAIL GOES HERE";
$subject = "Customer Enquiry";
$body = 'Name:'.$names .'Email:'.$email .'From:'.$from .'To:'.$dateto .'Details:'.$details;
mail ($to,$subject,$body);
echo "Thank you for your enquiry. Your Message has been Sent. You will be contacted as soon as is possible. <a href='http://www.stleonard.info/default.html'>Click/n;
echo $body;
?>
<body>
</body>
</html>
[/CODE]

  • 0

Variables in PHP are case-sensitive. Try using $_POST instead of $_post.

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;html xmlns="http://www.w3.org/1999/xhtml">;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name="input" action="send.php" method="post"/&gt;
Name:&lt;input type="text" name="names"/&gt;
Email:&lt;input type="text" name="email"/&gt;
Date From:&lt;input type="text" name="from"/&gt;
Date to:&lt;input type="text" name="dateto"/&gt;
Details:&lt;textarea name="details" rows="8" cols="30"&gt;&lt;/textarea&gt;
&lt;input type="submit" name="Submit" value="Send"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

and

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;html xmlns="http://www.w3.org/1999/xhtml">;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;send.php</title>;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
$names = $_POST['names'];
$email = $_POST['email'];
$from = $_POST['from'];
$dateto = $_POST['dateto'];
$details = $_POST['details'];
$to = "MYEMAIL GOES HERE";
$subject = "Customer Enquiry";
$body = 'Name:'.$names .'Email:'.$email .'From:'.$from .'To:'.$dateto .'Details:'.$details;
mail ($to,$subject,$body);
echo "Thank you for your enquiry. Your Message has been Sent. You will be contacted as soon as is possible.&lt;br /&gt;";
echo "&lt;a href='http://www.stleonard.info/default.html'>Clicke&lt;/a&gt;";
echo $body;
?&gt;
&lt;/body&gt;
&lt;/html&gt;

  • 0
  On 19/10/2011 at 16:07, IMcloud said:

It is a good practice to sanitize your input. Example:

$name = htmlspecialchars($_POST['name']);

Could you elaborate? - htmlspecialchars? - it is as you say in the code example below... Just dont understand what you mean by HTML Special Characters?


$names = $_POST['names'];
[/CODE]

  • 0

In practice, users can write anything in the provided form fields. Someone with malicious intents can insert harmful scripts in your page, access database with admin rights, execute shell commands etc., in other words, it's how most of the security breaches are being done.

It's the task of the programmer to prevent such attacks by outright removing such commands and returning an error to the user before doing anything else with them. If such information needs to be preserved (e.g., like any stuff between code tags in these forums) then most non-alphanumeric characters (e.g., tag braces < and >) need to be converted to HTML entities (respectively, < and >) and various other safety precautions followed.

This kind of stuff is likely overwhelming now, I tried to be concise. There are many methods and helpful functions (like htmlspecialchars() mentioned above); people write whole books about it alone. However, it's the most important thing to implement if site is intended for production use.

  • 0

For the benefit of those reading this forum also looking for help:

The resolved code, and the reason for its faliure.

HTML FILE (form.html)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>
<body>
<form name="input" action="send.php" method="post"/>
Name:<input type="text" name="names"/><br />
Email:<input type="text" name="email"/><br />
Date From:<input type="text" name="from"/><br />
Date to:<input type="text" name="dateto"/><br />
Details:<textarea name="details" rows="8" cols="30"></textarea><br />
<input type="submit" name="Submit" value="Send"/>
</form>
</body>
</html>
[/CODE]

PHP (send.php)

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>send.php</title>
</head>
<?php
$names = htmlspecialchars($_POST['names']);
$email = htmlspecialchars($_POST['email']);
$from = htmlspecialchars($_POST['from']);
$dateto = htmlspecialchars($_POST['dateto']);
$details = htmlspecialchars($_POST['details']);
$to = "enter your email here";
$subject = "Customer Enquiry";
$body = 'Name:'.$names .'Email:'.$email .'From:'.$from .'To:'.$dateto .'Details:'.$details;
mail ($to,$subject,$body);
echo "Thank you for your enquiry. Your Message has been Sent. You will be contacted as soon as is possible.<br />";
echo "<a href='http://www.stleonard.info/default.html'>Clicka>";
?>
</body>
</html>
[/CODE]

The probelm was:

[CODE]
$names = htmlspecialchars($_POST['names']);
$email = htmlspecialchars($_POST['email']);
$from = htmlspecialchars($_POST['from']);
$dateto = htmlspecialchars($_POST['dateto']);
$details = htmlspecialchars($_POST['details']);
[/CODE]

$_POST MUST BE CAPITAL - lowercase prevents data transfering from field to variable.

problem number 2:

[CODE]
echo "Thank you for your enquiry. Your Message has been Sent. You will be contacted as soon as is possible.<br />";
echo "<a href='http://www.stleonard.info/default.html'>Clicka>";
[/CODE]

That semi colon at the end of the code.... - a friend has said to me "everything i do in my day ends with a semi colon".

Ill certainly remember this when coding in PHP again.

Thanks for the advice

Alex

This topic is now closed to further replies.
  • Posts

    • Windows 11 is getting a useful new audio feature by Taras Buria Photo: phamtu1509 Windows 11, in its current form, does not offer a quick and easy way to play audio over more than one device. If you have a bunch of audio devices connected and you want to play music on all of them, you have to tinker with third-party software to make it work. Apparently, Microsoft wants to change that with a new feature coming soon to Windows 11. @phantomofearth, the ever-giving source of Windows insights, discovered that the latest Windows 11 preview builds have a hidden toggle in quick settings that lets you share audio to multiple devices with just a few clicks. All it takes is clicking "Shared Audio" in the control center, selecting two or more available devices, and pressing "Share." As usual, there are no official announcements yet, so details about this feature remain unknown. Still, you can probably expect the new shared audio feature to make it to a Windows 11 preview build in the near future. In other Windows Insider news, Microsoft recently revealed that one of the recent taskbar changes was pulled from the operating system due to negative feedback. The company experimented with a simplified taskbar tray area, but later decided to nuke it because people did not like it. Still, there are plenty of other features coming soon to Windows 11. Check out our recent top 10 list here. Hopefully, all of them will make it to the Stable channel soon.
    • Chinese? It sounds extremely dangerous. I’ll reconsider buying a Meta Quest 3.
    • - What's your salary? Is it more than $100k a year? - Nah, it's $100 mil a year.
    • Compared to my ear buds which are the size of a matchbox, cover a much broader frequency range, and work everywhere without setup? Yeah, still not buying this as a replacement.
    • Meta's Superintelligence team staffed by 50% Chinese talent, 40% ex-OpenAI by Hamid Ganji Mark Zuckerberg's latest big bet at Meta involves building a team of the best AI superstars in the market to lead the so-called Superintelligence Labs. The goal of this team is to develop AI models that will ultimately lead to Artificial General Intelligence (AGI). AGI refers to an AI model with capabilities comparable to, or even beyond, those of the human brain. Achieving human-level cognitive abilities with an AI model requires substantial investments, as well as hiring the best talent to build such a system. That's why Meta is throwing hundreds of millions of dollars at AI researchers from OpenAI, Apple, and other companies to recruit them for its Superintelligence team. A user on X has now shared a spreadsheet that provides us with some unique insights into Meta's Superintelligence team and the origins of its 44 employees. The leaker claims this information comes from an anonymous Meta employee. The listing claims that 50 percent of the staff at the Superintelligence team are from China, which demonstrates the significant role of Chinese or Chinese-origin researchers in Met's AI efforts. Additionally, 75 percent of these staff hold PhDs, and 70 percent of them work as researchers. Interestingly, 40 percent of the staff are ex-OpenAI employees whom Mark Zuckerberg poached from the maker of ChatGPT. Additionally, 20 percent of Meta's Superintelligence team members come from Google DeepMind, and another 15 percent come from Scale AI, a startup that Meta recently acquired in a $15 billion deal. Another interesting point is that 75 percent of the Superintelligence team are first-generation immigrants. The leaker claims that each of these employees is now earning between $10 million and $100 million per year, although Meta still needs to confirm these substantial figures. However, it has already been reported that Meta is offering up to $100 million in signup bonuses to poach the best AI talent from OpenAI and other rivals. The revelation that half of Meta's Superintelligence team consists of Chinese nationals could trigger concerns within the Trump administration and Congress.
  • Recent Achievements

    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      206
    4. 4
      Xenon
      138
    5. 5
      +FloatingFatMan
      112
  • Tell a friend

    Love Neowin? Tell a friend!