Reputation: 169
So the issue is I want multiple recipients for my PHP form.
What happens is the site user enters there email and then another email for another peroson (for example there doctor).
So what I need is the the doctor to be emailed to.
This is what I am using to know success
$mail_to = $field_emaildoc .$field_email;
This doesent seem to work?
Any ideas would be great :)
Thanks
Upvotes: 0
Views: 307
Reputation: 16828
one option is to add a "Cc" to your header:
$sender_email = '[email protected]';
$sender_name = 'YOUR NAME';
$send_to = '[email protected]';
$send_to_copy = '[email protected]';
$message = 'THIS IS YOUR MESSAGE';
$subject = 'THIS IS YOUR SUBJECT';
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= "From: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "X-Sender: $sender_name<" . $sender_email . ">" . "\n";
$headers .= "X-Mailer: PHP " . phpversion() . "\n";
$headers .= "X-Priority: 3" . "\n";
$headers .= "X-Sender-IP: " . $_SERVER['REMOTE_ADDR'] . "\n";
$headers .= "Return-Path: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "Reply-To: $sender_name<" . $sender_email . ">" . "\r\n";
$headers .= "Cc: $send_to_copy" . "\r\n";
mail($send_to,$subject,$message,$headers);
The problem with this, is that the person receiving the email can see who was copied in. An alternative would be to use: "Bcc" instead of "Cc" or just use the mail()
function twice and remove the "Cc" or "Bcc":
mail($send_to1,$subject,$message,$headers);
mail($send_to2,$subject,$message,$headers);
Upvotes: 1
Reputation: 27295
Use the default mail function from PHP.
The recipients are devided by a Comma.
When you want CC and BCC you can set the header. Example from PHP.net:
$header .= 'To: Simone <[email protected]>, Andreas <[email protected]>' . "\r\n";
$header .= 'From: Geburtstags-Erinnerungen <[email protected]>' . "\r\n";
$header .= 'Cc: [email protected]' . "\r\n";
$header .= 'Bcc: [email protected]' . "\r\n";
mail($empfaenger, $betreff, $nachricht, $header);
Upvotes: 0
Reputation: 6389
You'll need a comma:
$mail_to = $field_emaildoc . ',' . $field_email;
Upvotes: 0
Reputation: 7128
You should put comma between mail addresses . Look explanation of to parameter, here : http://php.net/manual/en/function.mail.php
Upvotes: 0