Jump to content

Mail() Function Wanting To Send MYSQL Query in Message


dlebowski

Recommended Posts

I have a basic mysql query that will return multiple results using mysql_fetch_row.  I want those results to be inserted in the the "$mail_body" portion of the email that is going out.  I cannot get this to work.  The only thing that will work is if I just use a standard "$variable" variable in the "$mail_body".  Can someone me with this?  Let me know if I need to elaborate.  Thank you.

 

<?php

$Name = "Da Duder"; //senders name
$email = "[email protected]"; //senders e-mail adress
$recipient = "[email protected]"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command 
?>

Does the text you are returning from the DB have any html tags in it? as I think this would cause it to fail.

 

You could try adding these to the headers

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

which should let it send ok. (its been a while since i have used e-mails with php though)

I want the results of this query, to be sent in the $mail_body. 

 

include("dbinfo.$companyname.inc.php");
mysql_connect("localhost",$uname,$pword)
or die("cannot connect");
mysql_select_db("$database")or die("cannot select DB");

$query45 = "SELECT itemspurchased FROM items WHERE ID = '1' LIMIT 1"; 
$result45=mysql_query($query45);
$num45=mysql_numrows($result45);
while ($row45 = mysql_fetch_row($result45))
{
 $itemspurchased = $row45[0];
}
								}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.