phpmailer不从表单中收集数据

时间:2017-08-19 04:11:57

标签: php phpmailer

这里有很多帖子说的和我一样,我已经尝试了为他们发布的所有修补程序,但没有一个有效。所以我完全失去了。

我在html页面上有表格,然后联系.php,但是对于我的生活,我无法通过它来获取任何数据。我已经玩了好几个小时了,但还是找不到它。

我已经尝试过如果为空且isset,并且没有任何工作,并且当电子邮件确实通过时,from也显示为Root User,当然是空的。所以我不知道该怎么做,我感谢大家提前帮助我解决这个问题。

HTML表格:

<form name="contactform" method="post" action="contact.php" >
   <input type="text" id="name" name="name" value="" spellcheck="false" 
      placeholder="Name*">
   <input type="text" id="email" name="email" value="" spellcheck="false" 
      placeholder="Email*">
   <input type="text" id="phone" name="phone" value="" spellcheck="false" 
      placeholder="Phone*">
   <select name="bustype" size="1" id="bustype">
      <option selected>Type Of Business*</option>
      <option value="retailer">Retailer</option>
      <option value="wholsaler">Wholsaler</option>
      <option value="distributor">Distributor</option>
   </select>
   <input type="text" id="units" name="units" value="" spellcheck="false" 
      placeholder="# of Units per Month*">
   <input type="text" id="locations" name="locations" value="" 
      spellcheck="false" placeholder="# of Locations*">
   <textarea name="message" id="message" rows="4" cols="44" spellcheck="false" 
      placeholder="Message*"></textarea>
   <input type="submit" id="Button2" name="submit" value="CONTACT US">
</form>

php邮件

<?php

$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$bustype = $_REQUEST['bustype'] ;
$units = $_REQUEST['units'] ;
$locations = $_REQUEST['locations'] ;
$message = $_REQUEST['message'] ;


require("../PHPMailer_5.2.0/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();


$mail->Host = "mail.mydomain.com";

$mail->SMTPAuth = true;


$mail->Username = "me@mydomain.com";
$mail->Password = "password";


$mail->From = $email;


$mail->AddAddress("me@someone.com");


$mail->WordWrap = 50;

$mail->IsHTML(true);

$mail->Subject = "Web Form Contact";

$mail->Body = '
<html>
<strong>Name:</strong> '.$name.'<br>
<strong>Email:</strong> '.$email.'<br>
<strong>Phone:</strong> '.$phone.'<br>
<strong>Business Type:</strong> '.$bustype.'<br>
<strong># of Units:</strong> '.$units.'<br>
<strong># of Locations:</strong> '.$locations.'<br>
<strong>Comments:</strong> '.$message.'<br>
</html>';
$mail->AltBody = 'This is a plain-text message body';

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

2 个答案:

答案 0 :(得分:0)

将$ _REQUEST替换为$ _POST,如下所示

$email = $_POST['email'] ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$bustype = $_POST['bustype'] ;
$units = $_POST['units'] ;
$locations = $_POST['locations'] ;
$message = $_POST['message'] ;
  1. 使用结束标记</form>
  2. 关闭表单

答案 1 :(得分:0)

我解决了这个问题。当我恢复原来的html表单时,我将enctype="text/plain"留在了表单标签中,并没有意识到。我真笨。一旦我删除了,一切都工作正常。