I have an auto email application that you guys helped with and it works. Only one problem it works sometimes and most of the time it sends errors stating a prob. with the email line. I think the problem is on the server and not code, cause if it was code it would not work at all. But what do I know?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>dirthound.com email_sender.php</title>
</head>
<body>
<p><strong>Private:</strong> For adminisrative use ONLY<br />
Write and send an email to mailing list members.</p>
<?php
require_once('appvars.php');
require_once('connectvars.php');
if (isset($_POST['submit'])) {
$from='example@example.com';
$subject=$_POST['subject'];
$text=$_POST['got_dirt_email'];
$output_form = false;
if (empty ($subject) && empty ($text)) {
echo 'You forgot the email subject and body text.<br/>';
$output_form = true;
}
if (empty ($subject) && (!empty ($text))) {
echo 'You forgot the email subject.<br/>';
$output_form = true;
}
if ((!empty ($subject)) && empty ($text)) {
echo 'You forgot the email body text.<br/>';
$output_form = true;
}
if ((!empty($subject)) && (!empty($text))) {
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
or die ('Error connecting to MySQL server.');
$query= "SELECT * FROM got_dirt";
$result= mysqli_query ($dbc, $query)
or die(' Error querying database.');
while ($row= mysqli_fetch_array($result)){
$to= $row['email_address'];
$first_name= $row['first_name'];
$last_name= $row['last_name'];
$msg="Dear $first_name $last_name,\n $text";
mail($to,$subject,$msg,'From:'.$from);
echo 'Email sent to:'.$to. '<br/>';
}// close while
mysqli_close($dbc);
} //close if ((!empty($subject)) && (!empty($text)))
}
else {
$output_form = true;
}
if ($output_form) {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<label for="subject">Subject of email:</label><br/>
<input id="subject" type="text" name="subject" size="60" value="<?php echo $subject; ?>"/><br/>
<label for="got_dirt_email">Body of email;</label><br/>
<textarea id="got_dirt_email" name="got_dirt_email" row="8" cols="60"><?php echo $text;?></textarea><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
}
?>
</body>
</html>