2016-08-23 223 views
0
$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 = "[email protected]"; 
    $email->Subject = "$from"; 
    $email->AddAddress("$email"); 

回顯$ email時,它返回人員的電子郵件地址。但是,將它放在雙引號中時,我收到一條錯誤消息,指出無法將對象轉換爲字符串。Sql查詢返回對象

感謝您的幫助,

aimmmmmmmmm

回答

2

點問題:

檢索電子郵件:

 $email = $row["email"]; 

實例化您的郵件:

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

Woops!那麼,謝謝你的幫助。 – aimmmmmmmmm