aimmmmmmmmm aimmmmmmmmm - 3 months ago 9
MySQL Question

Sql Query Returns Object

$sql = "SELECT email FROM users WHERE username='$User'";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$email = $row["email"];
}
}
echo $email;
require_once("class.phpmailer.php");;
$email = new PHPMailer();
$email->From = "clientinformation@apbdispatch.com";
$email->Subject = "$from";
$email->AddAddress("$email");


When echoing $email, it returns the persons email address. However, when putting it in double quotes, I get an error message stating that an object cannot be converted into a string.

Thanks for your help,

aimmmmmmmmm

Answer

Spot the problem:

retrieve the email:

        $email = $row["email"];

instantiate your mailer:

$email = new PHPMailer();
  ^---oops, now your database result is destroyed.
Comments