PHPMailer无法正常工作

时间:2013-10-19 06:24:40

标签: php phpmailer

我有一个看起来像这样的表格

<form action="send_attach_pear.php" type="POST" enctype="multipart/form-data">
<p>Name: <input type="text" name="name" id="name" /></p>
<input type="submit">
</form>

将信息发送到PHP文件...

require 'class.phpmailer.php';

$name = $_POST['name'];

//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->setFrom('from@example.com', 'First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('zacharycook2014@utexas.edu', 'Zach Cook');
$mail->Subject = 'PHPMailer mail() test';
$mail->isHTML(true);
$msg = "This is a message from " . $name . ".";             
$mail->Body = $msg;

但由于某种原因,“$ name”没有出现在最后的电子邮件中。

你知道出了什么问题吗?

1 个答案:

答案 0 :(得分:3)

method = POST而非type = POST

以下是代码:

<form action="send_attach_pear.php" method="POST" enctype="multipart/form-data">