2
$user_subject = 'new order';
$email_us = $_REQUEST['email'];
$name_us = $_REQUEST['name'];
$phone_us = $_REQUEST['phone'];
$qut = $_REQUEST['qut'];
$message_us = $_REQUEST['message'];
$email = "[email protected]";
$message = '<HTML><body dir="rtl">';
.
.
.
.
if(mail($email, $user_subject, $message, $headers)) {
$mess_err = "Successful message";  
}

I am trying to send a message to multiple e-mails. I have tried:

$email = "[email protected]"; "[email protected]"; 
// in this case is taking first one only

$email = array("[email protected]", "[email protected]");
// in this case it send me an error like: Warning: mail() expects parameter 1 to be string, array given

tried also converting it to string:

$emails = array("[email protected]", "[email protected]");
$email = array_shift($emails);

// in this case doesn't work at all

Please help me on this. I need to send a message to 2 emails instead of 1. How do i do this?

1
  • are you using phpmailer? Or better, which method are you using to send the email? Commented Jan 31, 2014 at 10:03

4 Answers 4

1
$emails = array("[email protected]", "[email protected]");
$email = array_shift($emails);

try this:

$emails = array("[email protected]", "[email protected]");
$email = implode(",",$emails);
Sign up to request clarification or add additional context in comments.

Comments

1

As per the PHP mail documentation, you have to use string concatenation, it seems.

From the docs:

The formatting of this string must comply with » RFC 2822. Some examples are:

You can concatenate strings with a dot:

$email = $email1 . "," . $email2;

or, if you have the emails in an array, you can use join:

$addresses = array("[email protected]", "[email protected]");
$email = join(",", $addresses);

which will then set $email to [email protected],[email protected]

Comments

0

try this...

mail("[email protected] , [email protected] , [email protected]","subject","message");

Comments

0

Multiple recepients will be comma separated, like so-

$email_id = "[email protected], [email protected]";

If $email_ids is an array of email ids, then

$email_id = implode(', ',$email_ids);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.