Problem while sending emails

I have a small script that sends an email to several users.

$to = $email1 . ", " . $email2 . ", " . $email3;
$subject = "Subject";
$headers  = 'MIME-Version: 1.0' . "\\r\
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\
$message = ''; // HTML message

Until now there are no problems. The problems start to appear if I want to send an email to the currently logged in user, based on their privilege:

// This section comes right after the first part above
if ($_SESSION['privilege'] < 2) {
  $message = '';
} else {
  $message = ''; // different HTML message

header('Location: home.php');

Now if I click on the form button, I don’t receive any more emails and the redirect to the homepage fails with a “File not found error”, telling me to check that the filename doesn’t contain uppercase letters or typos and to check if the file was moved, renamed or deleted.

Do you have any idea why this is happening?

Try putting something inside the messages.

LOL I may be stupid but not up to this point XD

The HTML messages are pretty long and contain information retrieved from a database, therefore it would have been useless to post them here in their entirety.

Here’s a test message:

$message = '
    <h1>Email title</h1>
    <p>Test message</p>

Any ideas?

Is there maybe another way to send different email messages to different email addresses?

is mail() returning true or false? Throw it into an if and use a variable on the end of the header to catch it.

The to parameter in the mail() function can only accept one email address. You might try adding the extra email addresses into the headers as a CC or BCC field.

// $to = $email1 . ", " . $email2 . ", " . $email3;
$subject = "Subject";
$headers = "Bcc: " . $email2 . ", " . $email3 . "\\r\
$headers  .= 'MIME-Version: 1.0' . "\\r\
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\
$message = ''; // HTML message
// mail($to,$subject,$message,$headers);

That statement is not correct. I regularly use multiple email addresses in the “to” field (separated by commas). The PHP spec also states that multiple recipients are permitted in the “to” field.

Please try this as I use this to send email to several addresses regularly via CRON . You may simply read any html file on your or any server and read and send same as html email.


$message = file_get_contents(‘’);

$to = “”;

$subject = "Your subject goes here ";

echo $message;

$headers = ‘MIME-Version: 1.0’ . "\r

$headers .= "Content-type: text/html\r

$headers .= ‘From: Your Name <>’ . "\r
$headers .= ‘To: Your Customer Name <>, Another Name <>,
Yet Another Name <>, One More Name <>’ . "\r
$headers.= ‘Cc:’ . "\r
$headers.= ‘Bcc:’ . "\r

mail($to, $subject, $message, $headers);