mail() $message truncating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
onalaska98
Forum Newbie
Posts: 5
Joined: Wed Jun 08, 2005 9:11 pm

mail() $message truncating

Post by onalaska98 »

Is there a limitation to how long your message can be when using mail()? I load the body of my html formatted email into $message and then call it to loop out my emails for a newsletter. However it seems to truncate the message around 1021 characters for whatever reason. I have tried removing all the html code from the message and it still truncates at the same amount of characters.

Code: Select all

<?php
if ($_POST[op] != "send") {
   //haven't seen the form, so show it
   print "
   <HTML>
   <HEAD>
   <TITLE>Newsletter Email</TITLE>
   </HEAD>
   <BODY>
   <form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
   <input type=\"hidden\" name=\"op\" value=\"send\">
   <p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
   </FORM>
   </BODY>
   </HTML>";

} else if ($_POST[op] == "send") {
    //want to send form, so check for required fields
    if (($_POST[subject] !="") || ($_POST[message] != "")) {
       header("Location: sendmymail.php");
       exit;
   }

   //connect to database
   $conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
   mysql_select_db("dbname",$conn)  or die(mysql_error());

   //get emails from subscribers list
   $sql = "SELECT user_email FROM users WHERE username = 'test'";
   $result = mysql_query($sql,$conn) or die(mysql_error());

   //create a From: mailheader
  $headers = "From: Name <name@domain.com>\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";
  $subject = "Subject is blah";
  $message = "<html><body>Big ol Message</body></html>";

   //loop through results and send mail
   while ($row = mysql_fetch_array($result)) {
       set_time_limit(0);
       $email = $row['user_email'];
    mail("$email", $subject, $message, $headers);
     print "newsletter sent to: $email<br>";
   }
}
?>
Am I doing something improperly? Perhaps I should be using a different method to send a long email? Any help offered would be appreciated!
Post Reply