PHPMailer function differences

4

In the documentation does not leave much explained this (I think), then, what would be the difference of:

I'm using the $mail variable for the example.

$mail->Username
$mail->setFrom
$mail->addAddress
$mail->addReplyTo

This last addReplyTo seems to be the email that will be in response, when we click on "reply" in our email (if not correct me). Can anyone else give an explanation?

    
asked by anonymous 13.04.2018 / 13:23

1 answer

5

Username : is the user used for authentication (and complementing Password ).

SetFrom : would be to add another email in place of what you are using for sending, but since everything today requires authentication for output, then it has no function. Unless you use an SMTP without authentication, but it's almost sure to go for spam.

AddAddress : you add more recipients (not in copy).

addReplyTo : As you said, it would be for the "answer", but if you use AddAddress , it responds to everyone, because they will be as members, not "copy."

Subject : is the subject of your email.

Body : the content of your email (it can be simple text or HTML).

AddEmbeddedImage : add "embedded" images.

SMTPDebug : to define the type of debug.

PHPMailer also already has a control in which it avoids duplicity of recipients, it filters itself and only arrow 1 if you report more equal.

A complete example:

// Cria objeto
$mail = new PHPMailer();

$titulo         = 'Teste';
$emailAssunto   = 'Exemplo de assunto';
$conteudo = 'Hello World :D';

$mail->Subject   = $emailAssunto;
$mail->Body      = $conteudo;
$mail->AddReplyTo('[email protected]');
$mail->setFrom('[email protected]', $titulo); // Basicamente para setar o título
$mail -> AddAddress('[email protected]');
$mail -> AddAddress('[email protected]');

// Define parâmetros
$mail->IsSMTP();
$mail->SMTPDebug  = 2;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )   
);
$mail->CharSet   = 'UTF-8';
$mail->Host      = $this -> srvNome;
$mail->Port      = $this -> srvPort;
$mail->Username  = $this -> srvEmail;
$mail->Password  = $this -> srvSenha;
//$mail->IsHTML(true);

// Envia o e-mail
if (!$mail->Send()) {
    echo "Erro ao enviar e-mail.";  
} else {
    echo "E-mail enviado !";
}

I have always used this concept. If you object, please comment.

    
13.04.2018 / 13:37