Manipuler les adresses du champ Bcc en php
:calim2::calim2::calim2::calim2::calim2::calim2::calim2::calim2:
Aidez moi svp, j'essaie de programmer une page d'envoi de plusieurs mails. Il s'agit d'un email pour plusieurs destinataires en Cc: ou Bcc:
Mon problème est que je ne sais pas comment manipuler la variable $_POST['bcc'] pour en extraire les adresses saisies par l'utilisateur.
Voici mon code html :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <form action="send_mail.php" method="post">
<span class="input input--chisato">
<input class="input__field input__field--chisato" name="nom" type="text" id="input-12" placeholder=" " required="" />
<label class="input__label input__label--chisato" for="input-13">
<span class="input__label-content input__label-content--chisato" data-content="Nom">Nom</span>
</label>
</span>
<span class="input input--chisato">
<input class="input__field input__field--chisato" name="prenom" type="text" id="input-13" placeholder=" " required="" />
<label class="input__label input__label--chisato" for="input-13">
<span class="input__label-content input__label-content--chisato" data-content="Prénom">Prénom</span>
</label>
</span>
<span class="input input--chisato">
<input class="input__field input__field--chisato" name="expediteur" type="email" id="input-14" placeholder=" " required="" />
<label class="input__label input__label--chisato" for="input-14">
<span class="input__label-content input__label-content--chisato" data-content="Email Expéditeur">Email Expéditeur: </span>
</label>
</span>
<span class="input input--chisato">
<input class="input__field input__field--chisato" name="bcc" type="text" id="input-14" placeholder=" " required="" />
<label class="input__label input__label--chisato" for="input-14">
<span class="input__label-content input__label-content--chisato" data-content="Emails clients">Destinataires Bcc: </span>
</label>
</span>
<span class="input input--chisato">
<input class="input__field input__field--chisato" name="subject" type="text" id="input-15" placeholder=" " required="" />
<label class="input__label input__label--chisato" for="input-15">
<span class="input__label-content input__label-content--chisato" data-content="Objet">Objet: </span>
</label>
</span>
<textarea name="message" placeholder="Message à envoyer..." required=""></textarea>
<input type="submit" value="Envoyer">
</form> |
Puis voici le code php de la page send_mail.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <?php
/**
* Created by PhpStorm.
* User: Computer
* Date: 27/05/2018
* Time: 02:41
*/
require("PHPMailer_5.2.0/PHPMailer_5.2.0/class.phpmailer.php");
$subject = $_POST['subject'];
$message = $_POST['message'];
// $message = wordwrap($message, 70, "\r\n");
$expediteur = $_POST['expediteur'];
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$bcc = $_POST['bcc'];
$mail = new PHPMailer();
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->From = $expediteur;
$mail->FromName = $prenom." ".$nom;
$mail->AddAddress("xxxxxx@hotmail.com", "prenom nom");
// $mail->AddAddress("yyyyyy@example.com"); name is optional
$mail->AddReplyTo($expediteur, $prenom." ".$nom);
if(empty($bcc)) {
}
else{
$mail->AddBcc = $bcc;
}
$mail->WordWrap = 70; // set word wrap to 50 characters
// $mail->AddAttachment("/var/tmp/file.tar.gz"); add attachments
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->Send())
{
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?> |
J'aimerais SVP récupérer les adresses insérées dans le champ BCC du formulaire pour renseigner , puis pouvoir contrôler le nombre de mails envoyés, vu que j'utilise le SMTP Google, et que le nombre d'envoi de message par jour est limité.
Merci d'avance pour toute contribution utile.:D:D:D:D