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

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
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

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

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

generally semi-colons ";" are used to separate email addresses
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Post 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!
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Post Reply