Hi,
I'm having an issue with a simple PHP mailer. I've had this script working, but it now doesn't work and I can't see for the life of me why not. It's instead spitting out the raw HTML rather than the rendered template.
If someone could have a browse and get back to me then that would be great. Thanks in advance.
<?php
if (isset($_POST['send']))
{
// explode the email addresses
$emails = explode(',', strtolower($_POST['to']));
// validate each email address
foreach ($emails as $id => $email) {
if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
die($email . ' is not a valid email address');
}
}
// all is good, let's send the emails out
$subject = 'Digital Pop Christmas Email';
$message = file_get_contents('index.html');
// loop through each recipient
foreach ($emails as $email) {
$to = $email;
$subject = 'Merry Christmas from Digital Pop';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $email . "\r\n";
$headers .= 'From: Digital Pop <[email protected]>' . "\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Email successfully sent to $email";
} else {
echo "Error sending email to $email";
}
echo "<br />\r\n";
}
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>PHP Mailer</title>
<meta http-equiv="author" content="[email protected]" />
</head>
<body>
<p>Send the <a href="./">Digital Pop Christmas Email</a>.</p>
<form action="?" method="post">
<fieldset>
<div><label for="to">To:</label> <small>(separate email addresses with commas)</small></div>
<div><textarea name="to" id="to" cols="50" rows="8"></textarea></div>
<div><input type="submit" name="send" value="Send" /></div>
</fieldset>
</form>
</body>
</html>