php电子邮件发送申请表

时间:2010-02-16 17:25:27

标签: php email

如何在PHP中创建使用mail()函数发送电子邮件的申请表?

3 个答案:

答案 0 :(得分:2)

最简单的PHP邮件。

<?php

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

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

?>

PEAR包MailMail_Mime也有许多用于发送邮件的有用功能。获取用户的输入,构建消息并发送消息。除此之外,我们需要知道你遇到了什么问题。

答案 1 :(得分:1)

非常简单的联系表格可能如下所示。请注意,这仅用于演示。我不建议原样使用它:

<?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>

答案 2 :(得分:1)

看看http://swiftmailer.org/,使用mail()函数没有正确的数据转发可能非常容易受到攻击和自定义标头注入。