I wrote the following script to send mail but it doesn't seem to work.

<?php
if($submit)
{
$db = mysql_connect("localhost", "d99kd", "mypass");
mysql_select_db("d99kd",$db);
$dbQuery="SELECT * FROM users where username='$theusername'";
$result = mysql_query($dbQuery,$db);
$userInfo=mysql_fetch_array($result);
$username=$userInfo["username"];
$password=$userInfo["password"];
$userFunctions=$userInfo["userFunctions"];
$firstName=$userInfo["firstName"];
$lastName=$userInfo["lastName"];
$emailAddress=$userInfo["emailAddress"];

$mailsubject = "Your password";
$mailbody = "Your Password is $password";

//if(mail($emailAddress, $mailsubject, $mailbody))
//{ echo "XXX good";
//}

$myname = "Darren Kane ";
$myemail = "darrenjkane@yahoo.co.uk";

$message = "Your password is $password - Don't forget it again!";
$subject = "Your Password";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$myname." <".$myemail.">\r\n";
$headers .= "To: ".$firstName.$lastName." <".$firstName.$lastName.">\r\n";
$headers .= "Reply-To: ".$myname." <$myreplyemail>\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Just My Server";

if (mail($emailAddress, $subject, $message, $headers))
{
echo "Good";
}
else echo "Bad";
}
?>

=============================================

It compiles ok but the mail doesn't get sent. Do any of you know why?

Also how do you include a picture attachment?

Thanks, D.

    Have you checked the the database data is being pulled out correctly?
    try print_r($userInfo);
    HTH
    Rob

      i agree with Ohlordy and i would try to force variable
      $emailAddress = 'your@email.com';

      if you just dont receive anything, something is wrong in php configuration, try php.net/mail for more details

      to send attachments needs a little hard work.. or you can look directly at
      http://phpmailer.sourceforge.net/

      []
      ic

        i looked at what you's said and i amended the code accordingly inserting echo statements where appropriate.

        The new file looks like this now....

        <?php
        if($submit)
        {
        $db = mysql_connect("localhost", "d99kd", "mypass");
        mysql_select_db("d99kd",$db);

            $dbQuery="SELECT * FROM users where eAddress='$theEMAIL'";
            $result = mysql_query($dbQuery,$db);
        
        $numrows = mysql_num_rows($result);
        
            echo 	"<html> \n" .
                    "  <head> \n" .
                    "    <title>Online Car Recommender System</title> \n" .
                    "    <link rel=stylesheet href=style.css> \n" .
                    "  </head> <br><br>" .
                    "  <body> \n " .
                    "    <p>&nbsp;</p> \n ";
        
        
        
        if($numrows==0)
        {
            echo 	"<p>&nbsp;</p> \n " .
        		"<p><font size=5 color=black style=bold><center>We do not have a record of <br>the entered email address in our system </center></font></p>\n" .
        	    	"<centeR><input type=button value='Back' onClick=\"javascript:history.back()\"> \n ";
            echo 	"	 <input type=button value='Welcome Page' onClick=\"document.location.href='welcome.php?status=logout'\"> ".
        		"</center>";
        }
        else
        {
            echo 	"<p>&nbsp;</p> \n " .
        		"<p><font size=5 color=black style=bold><center>Your user details have been sent to you<br> They will be arriving at your email address soon</center></font></p>\n" .
        	    	"<centeR><input type=button value='Back' onClick=\"javascript:history.back()\"> \n ";
            echo 	"	 <input type=button value='Welcome Page' onClick=\"document.location.href='welcome.php'\"> ".
        		"</center>";
        
        
            	$userInfo=mysql_fetch_array($result);
                $username=$userInfo["userID"];
                $password=$userInfo["password"];
                $firstName=$userInfo["fname"];
                $surname=$userInfo["sname"];
                $emailAddress=$userInfo["eAddress"];
        
        	echo "USERNAME: $username<br><br>";
        	echo "PASSWORD: $password<br><br>";
        	echo "FNAME   : $firstName<br><br>";
        	echo "SURNAME : $surname<br><br>";
        	echo "EMAIL   : $emailAddress<br><br>";
        
          	$subject = "Your Login Details";
          	$message = "Hello $firstName $surname \n Your Password is $password";
        
          //if(mail($emailAddress, $mailsubject, $mailbody))
          //{  echo "XXX good";
          //}
        
         	$myname = "CARS online"; 
        	$myemail = "darrenjkane@yahoo.co.uk"; 
        
        	$headers .= "MIME-Version: 1.0\r\n"; 
        	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        	$headers .= "From: ".$myname." <".$myemail.">\r\n"; 
        	$headers .= "To: ".$firstName.$surname." <".$emailAddress.">\r\n"; 
        	$headers .= "Reply-To: ".$myname." <$myemail>\r\n"; 
        	$headers .= "X-Priority: 1\r\n"; 
        	$headers .= "X-MSMail-Priority: High\r\n"; 
        	$headers .= "X-Mailer: Just My Server"; 
        
        	echo "<br><br> HEADERS <br> $headers <br><br>";
        	echo "<br><br> SUBJECT <br> $subject <br><br>";
        	echo "<br><br> MESSAGE <br> $message <br><br>";
        
          	//mail($emailAddress, $subject, $message, $headers);
        	//echo "XXX\n";
        
         	if(mail("", $subject, $message, $headers))
         	{
         		echo "<br><br> Good";
         	}
         	else echo "<br><br> Bad"; 
        
          }

        }
        ?>

        This produces all the correct print statements for the variables yet still echos bad at the end where the mail command is!

        Any other ideas anyone?

          Write a Reply...