Link to home
Start Free TrialLog in
Avatar of keithedwardb
keithedwardbFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP email string problem

Hi Experts,
I have a php page that for the most part works as designed.  I have one issue.
The page sends two emails, one after the other.
The first email only seems to work if one email address is used in 'To' section.  As soon as I try to concatanate a string that contains, say, 2 or more email addresses, the email fails to send.

The syntax I am using is:
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

for example if I use $pfw_email_to ="a.nother@isp.com";.  the function works fine and the email goes to a.nother@isp.com.

However, if I use, $pfw_email_to = "a.nother@isp.com; asecondperson@hotmail.com"; the email fails to send to either.  My original reason for looking at this is that I wanted to control the recipients from a string, so that if people change places / email address, etc I can simply have one string to alter leaving the base code intact.
Any ideas where my issue is, please?
Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Derokorian
Derokorian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would explode and then foreach to send a message:

$emails = explode(';',$pfw_email_to);
foreach($emails as $v){
	@mail($v, $pfw_subject ,$pfw_message ,$pfw_header ) ;	
}

Open in new window

Avatar of keithedwardb

ASKER

As they say in the English Language, you need to know when to use a comma and when to use a semi-colon - it applies equally to syntax.  Thanks for your help.  It was quick and painless and answered all my issues and saved many (more) hours of frustration.  The page now works perfectly.
Thanks again.