Specifications

Clicking the Send Message button invokes the “send-message” action, which executes the fol-
lowing code:
case ‘send-message’ :
{
if(send_message($to, $cc, $subject, $message))
echo “<p>Message sent.<br><br><br><br><br><br>”;
else
echo “<p>Could not send message.<br><br><br><br><br><br>”;
break;
}
This code calls the send_message() function, which actually sends the mail. This function is
shown in Listing 27.12.
LISTING 27.12 send_message() Function from mail_fns.phpThis Function Sends the
Message that the User Has Typed In
function send_message($to, $cc, $subject, $message)
{
//send one email via PHP
global $auth_user;
if (!db_connect())
{
return false;
}
$query = “select address from users where username=’$auth_user’”;
$result = mysql_query($query);
if (!$result)
{
return false;
}
else if (mysql_num_rows($result)==0)
{
return false;
}
else
{
$other = “From: “.mysql_result($result, 0, “address”).”\r\ncc: $cc”;
if (mail($to, $subject, $message, $other))
return true;
else
{
return false;
Building Practical PHP and MySQL Projects
P
ART V
650
33 7842 CH27 3/6/01 3:41 PM Page 650