Jump to content

email query rset


stvchez

Recommended Posts

I'm trying to email password results to users.  They are getting the results mailed to them, so that is working, but are just receiving the username in both fields.  here's my code and wonder where I am off..

 

$query = "SELECT username,password FROM tblNamesMain WHERE Email='$to'";

$result = mysql_query($query, $link);

 

$username=mysql_result($result,"username");

$password=mysql_result($result,"password");

 

$body = "Here is your user Athletic Endurance account information that you requested.\n\nUsername:  ".$username."\nPassword: " .$password." ";

 

mysql_close($conn);

 

if (mail($to, $subject, $body)) {

  echo("<p>Message successfully sent!</p>");

....

Link to comment
https://forums.phpfreaks.com/topic/42002-email-query-rset/
Share on other sites

Probably better to do it this way:

 

<?php
$query = "SELECT username,password FROM tblNamesMain WHERE Email='$to'";
$result = mysql_query($query, $link) or DIE(mysql_error());
$uData = mysql_fetch_assoc($result);

$username = $uData['username'];
$password = $uData['password'];

$body = "Here is your user Athletic Endurance account information that you requested.\n\nUsername:  ".$username."\nPassword: " .$password." ";

mysql_close($conn);

if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
?>

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42002-email-query-rset/#findComment-203664
Share on other sites

Mail headers are always good to include especially if you want to define reply-to etc.

 

I simply posted a solution to the reason why the username and password were not showing up. 

 

But redarrow is right, for this to be done the best way possible, mail headers are a must.

 

Some example headers for ya:

 

<?php
	$mail_headers = "From: Your Mailer <[email protected]>\r\n";
	$mail_headers .= "Reply-To: You at No Reply <[email protected]>\r\n";
	$mail_headers .= "MIME-Version: 1.0\r\n";
	$mail_headers .= "Content-type: text/plain; charset=utf-8\r\n";
	$mail_headers .= "X-Mailer: Your Mailer";	

                 mail($to, $subject, $body, $mail_headers, "-f" . "From: Your Mailer <[email protected]>\r\n");
?>

 

Anyhow hope the helps.

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42002-email-query-rset/#findComment-203680
Share on other sites

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.