PDA

View Full Version : PHP Only Sending To One Email



tomyknoker
05-03-2007, 10:41 PM
Hi all... I have the following


mail($to, "Membership Status", $msg, 'From: '.$from);

And then have this in the $to


$to = "domain1@email.com, domain2@email.com, domain3@email.com, domain4@email.com, domain5@email.com";

It's only sending to the first email... But in the email that get's sent to the first email address I can see all those email addresses in the to field... Any ideas?

ItsMeOnly
05-03-2007, 11:00 PM
I'd rather suspect your mail transport rather than PHP. What system are you on , what are your SMTP settings (and what software have you been using to send mail)?

tomyknoker
05-03-2007, 11:03 PM
I'm sending it through the server, it's a PHP page... Are you asking what software the server is running? It's a Windows IIS server...

ItsMeOnly
05-03-2007, 11:07 PM
I'm sending it through the server[...]It's a Windows IIS server...
And that can be the problem:
from PHP manual:

The Windows implementation of mail() differs in many ways from the Unix implementation.[...] a MTA is needed listening on a network socket.[...] to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA.
Therefore you need to check if your MTA, that receives the mail doesn't actually bounce it in the first place.

Ron_Hickey
05-03-2007, 11:07 PM
while ($to = "domain1@email.com, domain2@email.com, domain3@email.com, domain4@email.com, domain5@email.com";)
{

mail($to, "Membership Status", $msg, 'From: '.$from);
}

djr33
05-04-2007, 12:03 AM
Hmm... I don't think that would do it.

Using a while and running through each, splitting at a comma might.

But that will run infinitely, since $to will continuously assume the value of the string, without any factors changing.

thetestingsite
05-04-2007, 01:22 AM
Try this:



<?php

// All of the email addresses the message needs to be sent to
$addresses = Array('me@domain.com','you@domain.com','test@example.com','email@website.com');

//the subject of the message
$subject = 'Test Email';

//The body of the message
$msg = <<<HERE
This is the test email message. Change me to what you want the email to say
HERE;

foreach ($addresses as $to) {
mail($to, $subject, $msg, 'From: PHP Script <noreply@domain.com>');
}
?>


Hope this helps.

djr33
05-04-2007, 01:37 AM
You could replace the first thing with this and make it easier to write:
$addresses = explode(', ', 'me@domain.com, you@domain.com, test@example.com, email@web.com');

tomyknoker
05-04-2007, 06:31 AM
Guys thanks for the help... I'll give it a goadn keep you posted...

djr33
05-04-2007, 06:49 AM
Oh, oops. It should be ', ' not just ','
//Edited above

Rick2k7
05-05-2007, 01:29 PM
Try this:



<?php

// All of the email addresses the message needs to be sent to
$addresses = Array('me@domain.com','you@domain.com','test@example.com','email@website.com');

//the subject of the message
$subject = 'Test Email';

//The body of the message
$msg = <<<HERE
This is the test email message. Change me to what you want the email to say
HERE;

foreach ($addresses as $to) {
mail($to, $subject, $msg, 'From: PHP Script <noreply@domain.com>');
}
?>


Hope this helps.

Scripts like that are pretty server intense when using a foreach or while to send mail or something.

tomyknoker
05-06-2007, 11:15 AM
Hey guys... Awsome all worked I also have a html email which I am sending and it wasn't working with the original code, but when I used explode it seemed to work... Any ideas as to why?