Is there anything wrong in this script?

Hello everybody and my congratulations with the upcoming holidays.
I have two questions about this easy script.

  1. Do you see any visible problems with it?
  2. When I try to send out the offer to my mailing list, I sometimes get the 500 Internal Server error. How about the script’s execution time? Should I be concerned about it? Since that 500 error, I now send email by bulks, each bulk of 100 emails, to make sure I don’t run out of allowed execution time for a script.

Thanks for any help.

<?php
	session_start();
	if (!isset($_SESSION['login']) || !isset($_SESSION['sess_uid']) || $_SESSION['admin'] != 1)
	{
		header('Location:' . 'http://www.sitename.net/admin_dev/');
		exit();
	}

	//connect to db
	include $_SERVER['DOCUMENT_ROOT'] . '/inc/mysqli_connect.php';
	//prepare query
	$sql = "
	SELECT
		name, s_name, register_mail
	FROM
		man_users
	WHERE
		active = 'yes'
	";
	//query the db
	$result = mysqli_query($db, $sql)
	or die('Unable to fetch user data.');
	//calculate number of returned users
	$num_of_users = mysqli_num_rows($result);
	//see the need to send out any messages
	if ($num_of_users > 0)
	{
		while ($row = mysqli_fetch_array($result))
		{
			//reference data
			$name = $row['name'];
			$s_name = $row['s_name'];
			//lowercase name and last name
			$name = strtolower($name);
			$s_name = strtolower($s_name);
			//uppercase first letter
			$name = ucwords($name);
			$s_name = ucwords($s_name);
			
			$register_mail = $row['register_mail'];
			$register_mail = trim($register_mail);

			$boundary   = md5( time() );
			$date       = date( 'r' );
			
			//reference file
			$file = $_SERVER['DOCUMENT_ROOT'] . '/mails/offer.html';
			//read file into a string
			$html     = file($file);
			//replace place holders
			$element  = preg_replace("/FIELD_surname/",  $s_name,   $html);
			$element  = preg_replace("/FIELD_name/",  $name,   $element);
			$ausgabe  = implode("", $element);

$headers = <<<END
From: The Company Name <offers@sitename.net>
Date: $date
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"

END;

$message = <<<END
Content-Type: multipart/alternative
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

------------------
LIMITED TIME OFFER
------------------

Dear $name $s_name,

The offer message


--$boundary
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

$ausgabe

--$boundary--

END;

			$status = mail($register_mail, "Limited time offer: 30% OFF", $message, $headers);
			if ($status)
			{
				echo '<p>Email sent to ' . $register_mail . '</p>';
			}
		}
	}//if ($num_of_users > 0)
?>

What error messages (if any) is php giving? How many emails are you trying to send when your getting the “500 Internal Server Error”?

No, I am not getting any error messages. The script seems to be just fine, with no errors. I just got the 500 Internal error when I was trying to send around 1500 emails to people on my mailing list. So, I thought it must be something with the sript’s execution time. Tell me, when you want to send out emails to people on your list, do you send an email to all people at once, or it is best to do it in bunks, say by sending emails to 200 people at a time? Also, I heard that sending out way too many emails is bad because it may be considered as spamming buy email account providers. So, if hotmail gets 200 emails from one domain, it may consider it to be some kind of spam. Not sure if that is true but something to consider.
But now I know the possible problem with 500 Internal. It may be server’s setting. I contacted my providers… godaddy.com and told them about the problem. After a few minutes they told me there is a limit of 1000 emails per day. So, I cannot send out more than 1000. That might be reason for the problem.
Thanks for your interest,
Alex.