【问题标题】:phpmailer not sending variablesphpmailer不发送变量
【发布时间】:2016-04-25 12:12:17
【问题描述】:

我正在尝试使用 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 没有发送变量 请有人让我知道我哪里出错了。在此先感谢

【问题讨论】:

    标签: php variables phpmailer


    【解决方案1】:

    &lt;form&gt; 如果不隐含 POST 方法并且您使用的是 POST 数组,则默认为 GET 方法。

    所以改变

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

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

    【讨论】:

    • 做到了。感谢您的帮助
    • @Joel 考虑接受答案。以下是meta.stackexchange.com/questions/5234/… 然后返回此处并对勾号/复选标记执行相同操作直到它变为绿色的方法。这会通知社区,找到了解决方案。否则,其他人可能会认为问题仍然悬而未决,可能想要发布(更多)答案。这是双赢的事情;-)
    • Ayye Fred 我是你的#1 粉丝
    • @PhiterFernandes :-) 哎呀,谢谢。哦……停下来;你让我脸红了lol!
    • 或者,您可以使用 $_REQUEST 代替 $_POST,其中包含 $_GET$_POST$_COOKIE$_SESSION 超全局变量的合并数组(在 php.ini 中定义的顺序),然后您的表单将与 GET 或 POST 一起使用。
    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    相关资源
    最近更新 更多