PHP 4.4.1 mail() issue
Date: 05/31/06
(PHP Community) Keywords: php, mysql, html, database, sql, microsoft
Alright guys, I'm having a bit of a problem. I'm in the process of writing this small document-tracking application for my mother's work and was writing it on my own site. It worked almost perfectly except for some functionality that I had yet to add.
But when I went to upload it to the server it was supposed to be on, I found out they were running an older version (4.4.1) than the one I had been writing for (5.1.2). So, I went in to go fix the problems (like removing Try-Catch statements), and I seem to have gotten most of them worked out, except one: for some reason the mail() function isn't actually sending any mail.
I've tried it with many different email addresses and no luck. Now, the server this is currently on (the server it will have to be run from as well) is using Microsoft Exchange which I don't really know much about. We've been looking at some of the other applications that are run on this server with working mail functionality and can't figure out why this application isn't running.
//File Name: docFunctions.php
//Author: Lisa Obenauf
//
//For use by Union Station of Kansas City (http://www.unionstation.org) only.
function generateEmail()
{
//MYSQL DB Connection and Table selection removed for privacy puroses//
//Verify the connections to the Database and Table
if (!$email_connect || !$db_select)
{
die("Problem connecting or selecting a database.");
} //end if
//initialize variables
$sender = $_POST['docFrom'];
$attachment = $_FILES['docAttachment']['name'];
$headers = "From:" . $_POST['docFrom'] . "\r\n";
$headers .= "Reply-To:" . $_POST['docFrom'] . "\r\n";
$headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
$body = "
File: " . $_FILES['docAttachment']['name'] . "
Respond By:" . $_POST['docDue'] . "
" . $_POST['docDescription'] . "
";
//Verifies that a recipient has been selected. If not, an error is displayed.
if ($_POST['docTo1'] === "")
{
die("Please choose someone to receive the attached document.");
} //end if
else
{
//Initialization of the $query statement for INSERT
$query = "INSERT INTO `doc_tracking` ( `doc_id` , `doc_from` , ";
$query .= "`doc_to_1` , `doc_to_2` , `doc_to_3` , `doc_to_4` , `doc_to_5` , `doc_to_6` , `doc_to_7` , `doc_to_8` , `doc_to_9` , `doc_to_10` , ";
$query .= "`doc_route` , `doc_distribution` , `doc_due` , `doc_action_1` , `doc_action_2` , `doc_action_3` , `doc_action_4` , `doc_action_5` , ";
$query .= "`doc_action_6` , `doc_action_7` , `doc_action_8` , `doc_action_9` , `doc_action_10` , `doc_description` , `doc_attach` ) ";
$query .= "VALUES (NULL , '" . $_POST['docFrom'] . "', '" . $_POST['docTo1'] . "', ";
//Sets the recipient of the email
$recipient = $_POST['docTo1'];
//if there are more recipients, they are added to $recipient for use in mass mailing.
//The $query variable is also augmented with either the person's email address or NULL if no address was selected.
if ($_POST['docTo2'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo2'] . "', ";
$recipient .= ", " . $_POST['docTo2'];
} //end else
if ($_POST['docTo3'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo3'] . "', ";
$recipient .= ", " . $_POST['docTo3'];
} //end else
if ($_POST['docTo4'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo4'] . "', ";
$recipient .= ", " . $_POST['docTo4'];
} //end else
if ($_POST['docTo5'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo5'] . "', ";
$recipient .= ", " . $_POST['docTo5'];
} //end else
if ($_POST['docTo6'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo6'] . "', ";
$recipient .= ", " . $_POST['docTo6'];
} //end else
if ($_POST['docTo7'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo7'] . "', ";
$recipient .= ", " . $_POST['docTo7'];
} //end else
if ($_POST['docTo8'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo8'] . "', ";
$recipient .= ", " . $_POST['docTo8'];
} //end else
if ($_POST['docTo9'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo9'] . "', ";
$recipient .= ", " . $_POST['docTo9'];
} //end else
if ($_POST['docTo10'] === "")
$query .= "NULL ,";
else
{
$query .= "'" . $_POST['docTo10'] . "', ";
$recipient .= ", " . $_POST['docTo10'];
} //end else
//Initialization of the "Respond By" information
$dueBy = $_POST['docYear'] . "-" . $_POST['docMonth'] . "-" . $_POST['docDay'];
//Continuation and conclusion of the INSERT statement
$query .= "'" . $_POST['docRoute'] . "', 'all' , '" . $dueBy . "', NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , '" . $_POST['docDescription'] . "', '" . $attachment . "');";
//Email Information to be displayed to the user. Contains the information sent in the email.
echo "Document Number: " . $_POST['docID'] . "
";
echo "From: " . $_POST['docFrom'] . "
";
echo "To: " . $recipient . "
";
echo "Attachment: " . $_FILES['docAttachment']['name'] . "
";
echo "Respond By: " . $_POST['docMonth'] . "-" . $_POST['docDay'] . "-" . $_POST['docYear'] . "
";
echo $_POST['docDescription'];
//Inserts information into the Database
$result = mysql_db_query("test", $query);
//Checks to see if the email needs to be sent to each person Sequentially or all at once.
//If sequentially, then the e-mail is just sent to the first recipient, and will be sent to the rest of the recipients.
//through confirmation via a different form.
if ($_POST['docDistribution'] === "all")
mail($recipient, "", $description, $headers);
else
mail($_POST['emailTo1'], "File: " . $_POST['docAttach'], $body, $headers);
//verifies the successful insertion of the information into the database.
if (!$result)
{
die("Invalid Query: " . mysql_error() . "
");
} //end if
else
{
echo "Insert successful.
";
} //end else
} //end else
mysql_close();
} //end generateEmail()
Anyway, thanks for any advice you can give me. I appreciate it. I've wracked my brain, searched through my books and the internet, asked my friends, and now I'm asking you.
Cheers!
--Lisa
P.S. The code isn't fully compliant with any HTML/XHTML standards as of yet, because it is still in development. I am more concerned with functionality than with compliance, and will update any HTML to be as compliant as possible when everything is working, so I apologize for any weird tags and suchnot.
Source: http://community.livejournal.com/php/455409.html