phpmailer不从表单中收集数据



这里有很多帖子说着和我一样的事情,我已经尝试了为他们发布的所有修复程序,但没有一个奏效。所以我完全不知所措。

我在html页面上有表格,要联系.php,但是对于我的生活,我无法让它提取任何数据。我已经玩了几个小时了,一直无法弄清楚。

我已经尝试过如果为空并且是设置,并且没有任何工作,并且当电子邮件确实通过时,发件人也显示为 Root 用户,当然是空的。所以我不知道该怎么办,我提前感谢大家帮我弄清楚了这个问题。

网页表单:

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

将 $_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>

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

最新更新