使用我粘贴的教程并填写以下PHPMailer php文件并制作以下html表单。但是在发送之后出现错误“消息无法发送.Mailer错误:消息正文为空”。请帮忙。
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'xxx@gmail.com';
$mail->Password = 'xxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('xxx@gmail.com', 'Joe User');
$mail->addReplyTo('info@example.com', 'Information');
$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->From = $email;
$mail->FromName = $name;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
,这是表格
<form name="contactform" method="post" action="email.php">
<div class="input-text-container clear">
<input type="text" name="name" id="name" placeholder="Your Name"
class="input-text input-text-left">
<input type="text" name="email" id="email" placeholder="Your E-mail"
class="input-text input-text-right">
</div>
<textarea type="text" name="message" id="message" placeholder="Your
Message" class="textarea"></textarea>
<button type="submit" value="submit Form" class="submit">SUBMIT</button>
</form>
答案 0 :(得分:1)
您的脚本似乎依赖于可用作全局变量的请求参数。但这是一种非常罕见(并且不安全)的做法。
使用$_POST['message']
代替$message
,邮件正文应包含表单中的数据。对其他参数也一样。