Email phpmailer

Asked

Viewed 594 times

1

I’m creating a form that when filled sends a confirmation email, so far so good, but I wanted him to also send an email to me with the data filled in the form, follows 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;
  • 1

    It would not be enough to define the CC copy?

  • 1

    $mail->AddCC('[email protected]', 'Ciclano'); // Copia and //$mail->AddBCC('[email protected]', 'Fulano da Silva'); // Cópia Oculta Forehead

1 answer

0


Ideally you would use "hidden copy". You wouldn’t have to create another object to send a "copy" to you.


Using "for/cc/cco" in Phpmailer:

To add recipients ("for"), 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 them all together or, only one option or another.


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

Example:

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

In part "A Simple Example" of documentation, you can see that 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: Documentation by Phpmailer (v.6.0.5)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.