Page 1 of 1

I can't send php generated emails to more than 1!

Posted: Fri Apr 02, 2004 10:40 am
by dimitris
Look please at the above script:
I try to send emails to more than one person and i cannot receive anything!

Code: Select all

<?php
if(isset($HTTP_POST_VARS['submit'])){
	
		if((strlen($HTTP_POST_VARS['subject'])>0) AND (strlen($HTTP_POST_VARS['body'])>0)){
$body = preg_replace("#(?<!\r)\n#s", "\n", $body);
$m="you@mydomain.com";
$n="you2@mydomain.com";
$pros = $m.",".$n;
$headers = "From: me@mydomain.com\n
			To: My Friends\n
			Date: ".date("D, d M Y H:i:s") . " UT\n
			Reply-To:me@mydomain.com\n
			Subject: ".$subject."\n
			X-Mailer: PHP/".phpversion()."\n
			MIME-Version: 1.0\n";
mail($pros,$subject,$body,$headers);
echo "Mail sent to $pros";
}else{
echo'<strong>You have to fill both fields</strong>';
}
}

?>
If I send to only one e.g. $pros = $m; instead of $pros = $m.",".$n;
It works!
If I write $pros="you@mydomain.com,you2@mydomain.com";
works too!
How can i make a chain of receivers by joining many variables to one ($pros)?
My PHP version is 4.1.2

Posted: Fri Apr 02, 2004 11:03 am
by lostboy
generally semi-colons ";" are used to separate email addresses

Posted: Fri Apr 02, 2004 11:42 am
by dimitris
lostboy wrote:generally semi-colons ";" are used to separate email addresses
Yea but it works with commas "," when i use a variable with a single string
$pros="you@domain.com,you2@domain.com,you3@domain.com,you4@domain.com,you5@domain.com);

In a tutorial i read :http://www.codingclick.com/print.php?aid=8
i'll make a try with semicolons too!

Posted: Fri Apr 02, 2004 3:36 pm
by TheBentinel.com

Code: Select all

$m="you@mydomain.com"; 
$n="you2@mydomain.com"; 
$pros = $m.",".$n;
I assume in your real script, those aren't hardcoded addresses, but are coming from variables. Do the variables have newlines attached to them? $pros might be looking like this:
you@mydomain.com\n
,you2@mydomain.com

That would create the situation you've described I think.

Also, what underlying mail program are you using? If you're on Linux, what is sendmail linked to? If that program can't handle multiple recipients, that would bite you, too.

Posted: Fri Apr 02, 2004 4:03 pm
by m3mn0n
Place the addresses in an array variable, and loop through the mailing process with a foreach() loop that sifts through the array and extracts the recipients one by one.