HELP!! PHP mail not working
Posted: Sun Jan 09, 2011 10:44 am
OK, I had this working on an older version of my site and I really just copied and pasted most of the code to a new version of my site, and now my code inserts messages into the database, but it's not sending messages to the user's e-mail address. Thanks for your help!
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$tag = $_POST['state'] . $_POST['tag'];
?>
<?php
include("include/connect.php");
?>
<?php
$sql="INSERT INTO messages (name, tag, message, ip)
VALUES
('$_POST[name]','$tag', '$_POST[message]', '$ip')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
?>
<head><link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<a href="index.php"><div id="logo"></div></a>
<div id="content_topimage"></div>
<div id="content">
Your message has been sent. Please <a href="main.php">click here</a> to return to your account.
</div>
<div id="content_bottomimage"></div>
<?php
$tag = $_POST['state'] . $_POST['tag'];
$reply = $_POST['reply'];
$message = $_POST['message'];
$sender = $_POST['name'];
$count_query = mysql_query("SELECT COUNT(username) FROM users WHERE tag LIKE '".mysql_real_escape_string($tag)."'");
$rows = mysql_fetch_array($count_query);
if ($rows[0] != 0) {
$query = mysql_query("SELECT email FROM users WHERE tag LIKE '".mysql_real_escape_string($tag)."'");
while ($array = mysql_fetch_array($query)) {
$mail_address = $array['email'];
}
$to = $mail_address;
$subject = "{$sender} 'tagged' you!";
$message = $message;
$headers = "From: noreply@tagtexter.com" . "\r\n" . "Reply-To: {$reply}";
$mail = mail($to, $subject, $message, $headers);
if ($mail) { echo ''; }
//edit for production
else {
echo $mail_address;
}
}
else {
// Display alternate message informing visitor or whoever
// that there was no email address matching the tag
} ?>
</body>
</html>