I'm trying to send an email to several people within an array called $destinatario
.
For this I created a function called envia_email
.
But I'm having the following error:
Fatal error: Call to a member function AddBCC() on string in
What happens on the line:
$email->AddBCC($email, $name);
I do not know what it can be. Follow my code below.
<?php
$destinatario = array(
'[email protected]' => 'Person One',
'[email protected]' => 'Perqweson One',
);
function envia_email($destinatario,$titulo,$texto) {
// Inclui o arquivo class.phpmailer.php localizado na pasta phpmailer
include("Modules/phpmailer/class.phpmailer.php");
// Instanciamos a classe
$email = new PHPMailer();
// Informamos que a classe ira enviar o email por SMTP
$email->isSMTP();
// Configuração de SMTP
$email->Host = "xxxxxxx";
$email->SMTPAuth = true;
$email->SMTPDebug = false;
$email->Port = "587";
$email->Username = "xxxxxxx";
$email->Password = "xxxxxxx";
// Remetente da mensagem
$email->From = "xxxxxxx";
$email->FromName = "xxxxxxx";
// Destinatário do email
foreach($destinatario as $email => $name) {
$email->AddBCC($email, $name);
}
// Iremos enviar o email no formato HTML
$email->IsHTML(true);
// Define a mensagem (Texto e Assunto)
$email->Subject = "$titulo";
$email->Body = "$texto";
// Envia o e-mail
$email->Send();
}