J'ai un problème avec un simple mailer PHP. J'ai fait fonctionner ce script, mais ça ne marche pas et je ne vois pas pourquoi je ne le ferais pas. Il crache plutôt le HTML brut plutôt que le modèle rendu.PHP mail() erreur; Je ne peux pas voir pour regarder!
Si quelqu'un pouvait naviguer et me contacter, ce serait génial. Merci d'avance.
<?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>
L'URL de l'email est http://www.digitalpop.co.uk/xmas_email/ pour ceux qui souhaitent voir à quoi il doit ressembler. –
Que voulez-vous dire par Raw HTML? Contient-il du code PHP non analysé? –
Oui. Il crache les en-têtes après "MIME-Version: 1.0" puis la source de index.html. –