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.