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
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
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 <noreply@yourdomain.com>\r\n";
	$mail_headers .= "Reply-To: You at No Reply <noreply@yourdomain.com>\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 <noreply@yourdomain.com>\r\n");
?>

 

Anyhow hope the helps.

 

--FrosT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.