-3

I'm using PHPMailer on my website, but it returns an error:

You must provide at least one recipient email address. I've checked out the following pages looking for answers: https://github.com/PHPMailer/PHPMailer/issues/441 https://github.com/PHPMailer/PHPMailer/issues/429

None of those solved my problem.

This is the way it's set up:

<?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 Code

INSERT INTO user (Password, FirstName, LastName, Email) VALUES ('friends34', 'Kaser', 'Baddal', 'banh5@gmail.com');

2 Answers2

0

Check that if your $Email and $row['Email'] is returning any valid email address or not. you can try once with a hard coded recipient.

$mail->AddAddress('receipient@example.com');

I guess from your code, $Email and $row['Email'] are same value. so if $Email=$_REQUEST["Email"]; is getting valid email, you can use -
$mail->AddAddress($Email);

Ziaur Rahman
  • 157
  • 10
0

On top of the wrong port number, SQL injection vulnerability, plain-text passwords, that you're using an outdated version of PHPMailer, and have based your code on an obsolete example, you're not doing any error checking on the email address. Try this:

if (!$mail->addAddress($row['Email'])) {
    exit(htmlspecialchars($row['Email']) . ' is not a valid email address.');
}

(htmlspecialchars() is there to avoid adding an XSS vulnerability for a perfect score!)

Synchro
  • 35,538
  • 15
  • 81
  • 104