开发者

php email sending application form [closed]

开发者 https://www.devze.com 2022-12-20 13:46 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reason开发者_StackOverflowably answered in its current
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reason开发者_StackOverflowably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How do I make an application form in PHP that sends an e-mail using the mail() function?


PHP mailing at its simplest.

<?php

$message = "This is my e-mail message.";

mail('recipient@example.com', 'Message subject', $message);

?>

The PEAR packages Mail and Mail_Mime have a lot of useful features for sending mail, as well. Take the user's input, build a message, and send it along. Beyond that, we'll need to know what you're having trouble with.


A very simple contact form may look like this. Note that this is simply for a demonstration. I wouldn't suggest using this as-is:

<?php

  // If our form has been submitted
  if ($_POST["submit"]) {
    // Gather up some values
    $name   = $_POST["username"];
    $msg    = $_POST["message"];
    $errors = false;
    // If the name and message aren't empty
    if (!empty($name) && !empty($msg)) {
      // Email them to ourselves
      mail("me@mydomain.com", "Website Email", "{$name} says: {$msg}");
    } else { // If they are empty
      // Set an error message
      $errors = "Please fill out the form.";
    }
    // If we have errors as this point, show them
    if ($errors) print "<p>".$errors."</p>";
  }

?>
<form method="post">
  <p>Name: <input type="text" name="username" /></p>
  <p>Message: <textarea name="message"></textarea></p>
  <p><input type="submit" name="submit" /></p>
</form>


Tak a look at the http://swiftmailer.org/, using mail() function without proper data escaping could be very vulnerable for attacks and custom headers injection.

0

精彩评论

暂无评论...
验证码 换一张
取 消