phpmailer不发送变量

时间:2016-04-25 12:12:17

标签: php variables phpmailer

我正在尝试使用phpmailer从html表单发送用户的输入

表格就像这样

<form action="senditpm.php" role="form">
<input type="text" class="form-control" id="name" name="name"><br>
<input type="email" class="form-control" id="email" name="email">>br>
<input type="text" class="form-control" id="phone" name="phone">>br>
<input type="submit" value="Submit" class="submit-button btn btn-default">
</form>

senditpm.php就像这样

<?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$email= $_POST['email'] ;

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();              
$mail->Host = 'xxxxxxxxx';  
$mail->SMTPAuth = false;                               
$mail->Username = 'xxxxxxxx';                
$mail->Password = 'xxxxxxxx';                           
$mail->Port = 25; 

$mail->setFrom('xxx@xxxxs.co.uk', 'xxxxx');
$mail->addAddress('xxx@xxx', 'xxx xxxx'); 
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';


$mail->Body="
Name: $name <br>
Email: $email <br>
Phone: $phone <br>"; 

;

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
  } else {
echo 'Message has been sent';
  }
?>

当我填写表单并单击“提交”时,我会收到一封类似这样的电子邮件

名称:

电子邮件:

电话:

正如你所看到的,php并没有发送变量 请有人让我知道我哪里出错了。提前致谢

1 个答案:

答案 0 :(得分:6)

<form>默认为GET方法,如果没有隐含POST方法并且您正在使用POST数组。

所以改变

<form action="senditpm.php" role="form">

<form action="senditpm.php" role="form" method="post">
相关问题