1

我正在尝试发送 php 邮件,但我的 foreach 似乎有错误,因为邮件显示 html .. 这是我的代码:

 <form method="post">
        <fieldset>
          <legend>Contact Form</legend>
          <label for="fullname">Votre Nom :
            <input id="fullname" name="fullname" type="text" value="nelson" />
          </label>
          <label for="emailaddress" class="margin">Votre e-mail:
            <input id="email" name="email" type="text" value="" />
          </label>
          <label for="message">Message:<br />
            <textarea id="message" name="message" cols="40" rows="8"></textarea>
          </label>
          <p>
             <input id="submit-button" class="button gray stripe" type="submit" name="submit" value="Envoyer le message" />
          &nbsp;</p>
        </fieldset>
      </form>

      <?php
      foreach ($_POST as $value) {
    $value = strip_tags($value);
    $value = htmlspecialchars($value);
}

      $name = $_POST["fullname"];
      $email = "email:" .$_POST["email"];
      $message = "Nom: <br/>" .$name. "email:<br/> " .$email. "message: " .$_POST["message"];
      $to="email@hotmail.com";
      $suject="site internet";
      if (isset($_POST['submit'])) {
      mail($to, $suject, $message);
      echo"mail had been sent";
      }
      ?>

谁能帮帮我

4

3 回答 3

1

您需要在电子邮件中设置 Content-type 标头:

$name = $_POST["fullname"];
$email = "email:" .$_POST["email"];
$message = "Nom: <br/>" .$name. "email:<br/> " .$email. "message: " .$_POST["message"];
$to="email@hotmail.com";
$suject="site internet";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (isset($_POST['submit'])) {
mail($to, $suject, $message, $headers);
echo"mail had been sent";

您的消息正文也需要包含在<html>标签中。

于 2013-06-24T14:35:53.177 回答
1

你的 foreach 有点没用,就这样做。比循环更快

$name = strip_tags(htmlspecialchars($_POST["fullname"]));
$email = "email:" .strip_tags(htmlspecialchars($_POST["email"]));
$message = "Nom: <br/>" .$name. "email:<br/> " .$email. "message: " .strip_tags(htmlspecialchars($_POST["message";)); 
于 2013-06-24T14:31:18.763 回答
0

要发送包含 HTML 的电子邮件,您必须设置标题,以便电子邮件客户端知道电子邮件包含 HTML。您还必须将电子邮件正文设为 HTML 文档。

$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
mail($to, $suject, $message, $header);

然后在消息本身中:

<html>
    <head></head>
    <body>
        Content here
    </body>
</html>
于 2013-06-24T14:36:05.227 回答