Page 1 of 1

PHP mail() function

Posted: Wed Jan 12, 2005 6:53 pm
by Trmbne2000
Hello everyone, I am developing a website using a combination of Flash MX, PHP, and MySQL. The site allows users to log in, and also provides a lost password form where users can type in their username and email address; if the two values match, the PHP script sends an email with the user name and password combination.
Here is the script that I have so far:

Code: Select all

<?php
$Name=$UName;
$Address=$Email;
$server="localhost";
$login="ht08orga_master";
$password="utprosim";
$link = mysql_connect($server, $login, $password);
mysql_select_db('ht08orga_BBBTest',$link);
if (!$link) &#123;
   die('Could not connect: ' . mysql_error());
&#125;
print "&status=Connected successfully, $Name, retrieving data.";
$query = "SELECT id, Email, FName, Password, UserName FROM users WHERE UserName = '$Name' AND Email = '$Address'";
$data = mysql_query($query);
while ($row = mysql_fetch_assoc($data)) &#123;
$id = $row&#1111;'id'];
$Contact = $row&#1111;'FName'];
$Password = $row&#1111;'Password'];
$User = $row&#1111;'UserName'];
&#125;
if (!$data) &#123;
 die("&status=No login data exists for the specified user, please try again.");
&#125;
else 
&#123;
 print "&status=$Contact, your login information has been sent to your email address at $Email";

/* subject */
$subject = "Password reminder from www.BruinBand.net";

/* message */
$message = "$Contact, this automated email is to give you your password so you can log in successfully. If you did not request this email, it means that someone may have made an attempt to access your account.\r\n
If this is the case, please contact us at Hostmaster@bruinband.net to resolve the issue.\r\n
Here is the information that you requested:\r\n\n
---------------------------------------\r\n
User Name: $User\r\n
Password: $Password\r\n
---------------------------------------\r\n\n
Thank you for visiting www.BruinBand.net, we hope you come back to visit soon.
";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: $Email\r\n";
$header .= "From: Bruin Band Hostmaster <webmaster@ht08.org>\r\n";
$header .= "Reply-To: Bruin Band Hostmaster <Hostmaster@bruinband.net>\r\n";


/* and now mail it */
mail($Address, $subject, $message, $headers);
&#125;
?>
The $UName, and $Email values are passed from the flash movie to the PHP script. I know that the script works, because when I type in a set of accepted values, it sends the email. But I'm having a few problems with it:
1) It also sends the email to unknown user name and email combinations.

2) Even though I have the Content-Type as HTML, when I attempt to send the message with HTML tags, they appear as text.

3) It sends two email as opposed to one.

4) And finally, Outlook displays the email as from "root@host255.iPowerWeb.com" as opposed to "Hostmaster@bruinband.net" like I have the Reply to set as.

If anyone can help me with any or all of these problems, I would greatly appreciate it.

Thankyou,
--Andrew Steenbuck

Posted: Wed Jan 12, 2005 6:59 pm
by feyd
the From and Reply-to addresses are sent to $header, not $headers.

and text/html .. ;)

Posted: Wed Jan 12, 2005 7:04 pm
by Trmbne2000
Thank you, as you can probably it's pretty much my first time writing PHP (this is only my second script), and I've pretty much been teaching my self from the manual on PHP.net.

Thanks,

--Andrew Steenbuck