我在网站上使用PHPMailer,但返回错误:
您必须至少提供一个收件人电子邮件地址。 我已经检查了以下页面以寻找答案: https://github.com/PHPMailer/PHPMailer/issues/441 https://github.com/PHPMailer/PHPMailer/issues/429
没有一个能解决我的问题。
这是它的设置方式:
<?php
$conn=mysqli_connect("localhost","sar","siarth2");
mysqli_select_db($conn,"test");
$Email=$_REQUEST["Email"];
$query=mysqli_query($conn,"select * from user where Email='$Email'");
$row=mysqli_fetch_array($query,MYSQLI_ASSOC);
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com";
$mail->SMTPAuth = TRUE;
$mail->Username = "sidban5679@gmail.com";
$mail->Password = "password";
$mail->Port =466;
$mail->From = "sidban5679@gmail.com";
$mail->FromName = "Sidharth";
$mail->AddAddress($row["Email"]);
$mail->isHTML(true);
$mail->Subject = "Password";
$mail->Body = "<i>this is your password:</i>".$row["Password"];
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
SQL代码
插入user
(Password
,FirstName
,LastName
,Email
)值
(“ friends34”,“ Kaser”,“ Baddal”,“ banh5@gmail.com”);
答案 0 :(得分:0)
检查您的$Email
和$row['Email']
是否返回任何有效的电子邮件地址。
您可以尝试使用硬编码的收件人。
$mail->AddAddress('receipient@example.com');
我猜从您的代码来看,$Email
和$row['Email']
是相同的值。因此,如果$Email=$_REQUEST["Email"];
收到有效的电子邮件,则可以使用-
$mail->AddAddress($Email);
答案 1 :(得分:0)
除了使用错误版本的端口号,SQL注入漏洞,纯文本密码之外,您还使用了过时的PHPMailer版本,并且代码基于过时的示例,因此您并未对任何错误进行检查电子邮件地址。试试这个:
if (!$mail->addAddress($row['Email'])) {
exit(htmlspecialchars($row['Email']) . ' is not a valid email address.');
}
({htmlspecialchars()
可以避免添加XSS漏洞以获得满分!)