PHPMailer发送没有表单数据的邮件

时间:2014-05-21 07:57:00

标签: php html css forms email

我有一个联系页面的css div html表单,希望在发送时通过电子邮件发送表单。作为PHP的新手我已经尝试了不同的例子,可以发送邮件,但无法在电子邮件中获取表单数据。

html代码

           <div class="maincontent">
  <div class="content">
  <article class="topcontent">
  <content>
  <div id="form-main">
  <div id="form-div">
  <form method="post" enctype="text/plain" action="mail.php" class="form" id="form1">
  <p class="name">
  <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
  </p>
  <p class="email">
  <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
  </p>
  <p class="text">
  <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Comment"></textarea>
  </p>
  <div class="submit">
  <input type="submit" value="SEND" id="button-blue"/>
  <div class="ease"></div>
  </div>
  </form>
  </div>
  </content>    
  </article>
  </div>
  </div>

PHP邮件脚本

    <?php
require("class.phpmailer.php");
$formcontent="From: $name \n Message: $text \n Email: $email";
$mail = new PHPMailer();
$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "localhost;";  // specify main and backup server
$mail->SMTPAuth = false;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender 
$message = $_POST['text']; // Your message
$mail->AddAddress('warren@.com', 'recipient email');
$mail->From = "noreply@.com";
$mail->FromName = "Contact Us Information";
$mail->Subject = "Website Contact Us Information";
$mail->Body = "Name:{$name}\n\nEmail:{email}\n\nComments:{$body}";
$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>

就像我说的那样,邮件已发送但没有表格信息。

由于

1 个答案:

答案 0 :(得分:0)

从表单标记中取出enctype="text/plain"

使用此功能无法获取发布的数据。