We help IT Professionals succeed at work.

PHP email string problem

keithedwardb
keithedwardb asked
on
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.
Comment
Watch Question

Concatenate with comma not semi colon
Greg AlexanderLead Developer

Commented:
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

Author

Commented:
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.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.