Erratic results using mail() with foreach appendages?

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
chandrika
Forum Newbie
Posts: 10
Joined: Fri Feb 05, 2010 11:20 am

Erratic results using mail() with foreach appendages?

Post by chandrika »

I am having alot of difficulty getting a script to send an email of some results.

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;
chandrika
Forum Newbie
Posts: 10
Joined: Fri Feb 05, 2010 11:20 am

Re: Erratic results using mail() with foreach appendages?

Post by chandrika »

oh no... :oops:
Nothing wrong with the code...just checked gmail spam folder. That is 4hrs of my life i wont get back...but i guess next time i would check sooner, so i learnt something at least.
Post Reply