send email with mysql results

Hello!

I just start using PHP and I think that I my question is so easy for you.

What I like to do, relations can submit their e-mail address at our website to receive their details from our mysql.
If the e-mail address is in the database we will send the details to that address.
Their can be multiply records with this address so I like put the results in a table.

What I build gives only one record without a table? Who is so kind to help me out, greetings from Haarlem, the Netherlands

$host="
$username=
$password="
$db_name="

mysql_connect("$host", “$username”, “$password”)or die(“cannot connect to server”);
mysql_select_db("$db_name")or die(“cannot select DB”);

$email_to=$_POST[‘email_to’];

$tbl_name=reservation;

$sql=“SELECT firstname, lastname FROM $tbl_name WHERE email=’$email_to’”;
$result=mysql_query($sql);

{

$rows=mysql_fetch_array($result);

$firstname=$rows[‘firstname’];
$lastname=$rows[‘lastname’];

$to=$email_to;

$subject=“Your details”;

$header="from: your name ";

// Your message
$messages= “Your details rn”;
$messages.=“Your firstname is $firstname rn”;
$messages.=“Your lastname is $lastname rn”;
$messages.=“bla bla. rn”;

$sentmail = mail($to,$subject,$messages,$header);

}

if($sentmail){
echo “Your details are sent to your Email Address.”;
}
else {
echo “Cannot send password to your e-mail address”;
}

?>

Okay, first of all, it would be best to put your code between [php] tags, so it’s highlighted. Makes it easier on all of us :slight_smile: Second, I’ve done a bit of a cleanup, as there was a lot of wrong syntax (and I’m a syntax nazi).

[php]

<?php $host = "YOURHOST"; $username = "YOURNAME"; $password = "YOURPASS"; $db_name = "YOURDATABASE"; mysql_connect($host, $username, $password) or die ("cannot connect to server"); mysql_select_db($db_name) or die ("cannot select DB"); $email_to = $_POST['email_to']; $tbl_name = "reservation"; $sql = "SELECT firstname, lastname FROM ".$tbl_name." WHERE email='".$email_to."'"; $result = mysql_query($sql); $rows = mysql_fetch_array($result); $firstname = $rows['firstname']; $lastname = $rows['lastname']; $to = $email_to; $subject = "Your details"; $header = "from: your name "; // Your message $messages = "Your details rn"; $messages .= "Your firstname is $firstname rn"; $messages .= "Your lastname is $lastname rn"; $messages .= "bla bla. rn"; $sentmail = mail($to,$subject,$messages,$header); if ($sentmail) { echo "Your details are sent to your Email Address."; } else { echo "Cannot send password to your e-mail address"; } ?>

[/php]

Now, we’d like to have some extra information regarding your issue:

What does your script (not) do what it should(n’t)?
Do you get any errors, if so, which ones?
What have you found by searching google/php.com/phphelp.com?
Why did what you found not suit your needs?

Many thanks for your input!
I don?t get any errors, I just like to see that the results in the e-mail are listed in a table (their can be multiply results) and not shown as I made:

$messages .= “Your firstname is $firstname rn”;
$messages .= “Your lastname is $lastname rn”;

I am really looking for this answer for days, using all kind of websites

Hmmz, I’m not sure if putting HTML in an email is such a smart idea, mainly because the receiver might have turned on ‘plain text only’ when viewing their emails. Other than that, tables are pretty basic HTML knowledge and have little to do with PHP.

Sponsor our Newsletter | Privacy Policy | Terms of Service