Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Coding PHP file Troubles

Guest
Jan 28, 2011 Jan 28, 2011

Hi, I am having troubles figuring out how to code the php file and have researched it for days. I am new to this so that could be the

huge proble. I want to add a form with one question to a web page and have the information sent to my emails. Can you help me with the coding of the php file?

Thank you in advance!

php file code:

<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('npolen@theram.com', 'Feedback Form Answer', $message);
?>

question sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html                                     >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="GET" action="/form/send_mail3.php">
  <label for="dancemove">What is your favorite dance move?</label>
  <input type="text" name="dancemove" id="dancemove" />
  <input type="submit" name="send" id="send" value="Submit" />
</form>
</body>
</html>

TOPICS
Server side applications
358
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2011 Jan 29, 2011
LATEST

Sending the contents of an online form by email is basically a question of gathering the values from the form, using the same name attribute as in the form.

Since you are using the GET method, the value of your "dancemethod" text input field can be accessed using the variable $_GET['dancemethod']. So, a very basic mail processing script would look like this:

<?php

if (isset($_GET['dancemethod'])) {

  $to = 'me@example.com'; // use your own email address

  $message = 'My favourite dance method is ' . $_GET['dancemethod'];

  $sent = mail($to, 'Feedback form result', $message);

  if ($sent) {

    echo 'Mail sent';

  } else {

    echo 'Failed';

  }

?>

As I say, this is a very basic script. If you are planning to use PHP, you need to learn how to use the language properly, rather than just relying on copying and pasting code from online tutorials. Online forms are an open invitation to spammers and hackers. Unless you understand what the script is doing, you run the risk of being attacked.

The script I have provided doesn't include any security checks, so it wouldn't stop spammers from trying to fill your inbox with rubbish.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines