Email phpmailer [duplicate]

1

I'm creating a form that when completed sends a confirmation email, so far so good, but I wanted it also sent an email to me with the data filled in the form, the client wants that information go to his email , I'm using phpmailer, follow below my code

/* Recuperar os Dados do Formulário de Envio*/
$client = $_POST["client"];
$clientIn = $_POST["clientIn"];
$email = $_POST["email"];
$telComercial = $_POST["comercial"];
$celular = $_POST["celular"];
$whats = $_POST["whats"];


/* Extender a classe do phpmailer para envio do email*/
require_once("phpmailer/class.phpmailer.php");


function smtpmailer($para, $de, $nomeDestinatario, $assunto, $corpo) { 
    global $error;
    $mail = new PHPMailer();
    /* Montando o Email*/
    $mail->IsSMTP();            /* Ativar SMTP*/
    $mail->SMTPDebug = 0;       /* Debugar: 1 = erros e mensagens, 2 = mensagens apenas*/
    $mail->SMTPAuth = true;     /* Autenticação ativada */
    $mail->SMTPSecure = 'ssl';  /* TLS REQUERIDO pelo GMail*/
    $mail->Host = 'xxxxxx'; /* SMTP utilizado*/
    $mail->Port = 465;             /* A porta 587 deverá estar aberta em seu servidor*/
    $mail->Username = '[email protected]';
    $mail->Password = 'xxxx';
    $mail->SetFrom($de, $nomeDestinatario);
    $mail->Subject = $assunto;
    $mail->Body = $corpo;
    $mail->AddAddress($para);
    $mail->CharSet = 'UTF-8'; // Charset da mensagem (opcional)
    $mail->IsHTML(true);

/* Função Responsável por Enviar o Email*/
if(!$mail->Send()) {
    $error = "<font color='red'><b>Mail error: </b></font>".$mail->ErrorInfo; 
    return false;
} else {
$error = "<font color='blue'><b>Mensagem enviada com Sucesso!</b> 
</font>";
    return true;
}
}

/* Passagem dos parametros: email do Destinatário, email do remetende, nome do remetente, assunto, mensagem do email.*/
 if (smtpmailer($email, 'xxxx', "xxx","xxx", $corpoMensagem)) {
     Header("location: sucesso.php"); // Redireciona para uma página de Sucesso.
}
if (!empty($error)) echo $error;
    
asked by anonymous 26.06.2018 / 20:32

1 answer

0

Ideally you should use "hidden copy". You would not have to create another object to send a "copy" to you.

Using "para / cc / cco" in PHPMailer:

To add recipients (" to "), use $mail->AddAddress() :

$mail->AddAddress('[email protected]', 'Pessoa A');
$mail->AddAddress('[email protected]', 'Pessoa B');
...

To add "with copy" (" cc "), use $mail->AddCC() :

$mail->AddCC('[email protected]', 'Pessoa C');
$mail->AddCC('[email protected]', 'Pessoa D');
...

To add "with hidden copy" (" cco "), use $mail->AddBCC() :

$mail->AddBCC('[email protected]', 'Pessoa E');
$mail->AddBCC('[email protected]', 'Pessoa F');
...

You can use all together, or just one option or another.

PS : The "name" of the recipient is not required .

Example:

$mail->AddBCC('[email protected]');

In the " A Simple Example " section of documentation , you can see the formats:

//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

Source: PHPMailer Documentation (v.6.0.5)

    
28.06.2018 / 12:44