-1

Hello I'm a beginner in php, MySQL, and html and I'm trying to use the MySQL database to send an email from php. I have the user enter whether they want an email receipt on an HTML page, they enter "Y" if they do. If they say yes then I use their primary key to grab their email address from the database (They can only use this form if they already exist in the database). Once I do this I try to use the query result in the mail() function in php.

The query is:

$s = "select mail from AA where UCID = '$UCID'";

I run and store the result:

($t = mysqli_query( $db, $s )) or die ("<br>SQL Error: " . mysqli_error($db) );

I then try to send the email:

mail($t, "Your Recent Transaction", "Test");

When I run the code I get this error in my html file:

Warning: mail() expects parameter 1 to be string, object given in /afs/cad.njit.edu/u/h/k/hk363/public_html/download/depositORwithdraw.php on line 54

I tried surrounding $t in quotes ("$t") but that didn't seem to work either, any solutions?

Thank You!

Shidersz
  • 16,846
  • 2
  • 23
  • 48
HashimKh
  • 17
  • 1
  • 1
    please read [how to prevent SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) – danblack Oct 21 '18 at 02:17

1 Answers1

-1

mysqli_query() returns an object. You need to extract the data from it, like:

mail(mysqli_fetch_assoc ( $t)["mail"], "Your Recent Transaction", "Test");
Ernani Azevedo
  • 461
  • 2
  • 6