Home » Php » email – How to send a mail to several people with the mail function of php?

email – How to send a mail to several people with the mail function of php?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have this piece of code that allows me to send a mail to one person that works, but I’d like to send it to two people at the same time, but when I put

$mail = $mail_alert_mountainwear,$mail_alert_mountainwear2; 

it doesn’t work…
How to send a mail to several people ?

if ($_POST['type'] == "E") {
        $mail = $mail_alert_mountainwear; //Address retrieved from my database
        $message_txt = "Salut Raph, je viens de reserver du matériel sur la plateforme de Réservation.\n Matériel Réservé: ".$room_name."\n A partir de: ".$_GET["res_start_date"]."\n jusqu'à: ".$_GET["res_end_date"]."\n Resonsable: ".utf8_decode($_POST['owner'])."\n ";
        $message_html = "<html>
                                                <head>
                                                </head>
                                                <body>
                                                <b>Salut Raph</b>, je viens de reserver du matériel sur <a href=\"http://reservation/quick/\" target=\"_blank\">la plateforme de Réservation</a>.<br><br>
                                                Matériel Réservé: ".$room_name."<br>
                                                A partir du: ".$_GET["res_start_date"]."<br>
                                                </body>
                                        </html>";

     }

        //=====Création de la boundary
        $boundary = "-----=".md5(rand());
        //==========


        //=====Création du header de l'e-mail.
        $header = "From: RCE | Reservation <[email protected]>".$passage_ligne;
        $header.= "Reply-to: \"".utf8_decode($_POST['owner'])."\" <".$_SESSION['user']."@ripcurl-europe.com>".$passage_ligne;
        $header.= "Cc: \"".utf8_decode($_POST['owner'])."\" <".$_SESSION['user']."@ripcurl-europe.com>".$passage_ligne;
        $header.= "Cci: \"Mountainwear Administrator\" <". $mail_alert_mountainwear2 ."@ripcurl-europe.com>".$passage_ligne;
        $header.= "MIME-Version: 1.0".$passage_ligne;
        $header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
        //==========


mail($mail;$sujet,$message,$header);
How to&Answers:

Try this

This will treat the value of $mail as a string, which the first parameter of the mail function is expecting:

mail(string $to, string $subject, string $message..

Solution:

$mail = $mail_alert_mountainwear . ', ' . $mail_alert_mountainwear2;