I have tried so many different ways of doing it, but can not find what I am doing wrong. I have some php code to send the values of an array as the $message variable. If I echo the variable $message, it is displayed correctly, but the email is not always sent. If I remove the foreach statement and just have a simple variable for $message, the mail sends every time. Is there some reason why sometimes the code sends the email, but most of the time it does not? Can anyone see what may be causing this script to act erratically in terms of actually sending the mail? It can not be the server settings, as it is only with the foreach appendages that the problem occurs.
Code: Select all
$text = "The titles of the books are <br /> ";
foreach($lc_title as $title)
{
$text .= $title;
$text .= "<br />";
}
//I put this after reading 70 characters max per line as some of the titles are more, it is same result with or without this added wordwrap
$message = wordwrap( $text, 50, "\n", true ) ;
$to = "mail@mail.com";
$subject = "Book Titles";
$from = "server@mysite.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo $message;