Username
: is the user used for authentication (and complementing, the Password
).
SetFrom
: would be to add another email in place of the one you are using for sending, but as everything today requires authentication for output, so it has no function. Unless you use an SMTP without authentication, but it is almost certain to go to spam.
AddAddress
: you add more recipients (not in copy).
addReplyTo
: as you said, it would be for the "reply", but if you use the AddAddress
, he responds to all, because they will be as members, and not "in copy".
Subject
: is the subject of your email.
Body
: the content of your email (simple text or HTML).
AddEmbeddedImage
: add "inline images".
SMTPDebug
: to define the debug type.
Phpmailer also already has a control in which it avoids the duplicity of the recipients, itself filters and arrow only 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 !";
}
Always used under this concept. If any objection, please comment.
Show RBZ, thanks! Just one more kk doubt, Subject would be the title of the emails? I saw here now and hit this question too.
– Lucas de Carvalho
I fixed Subject and added a full sample script. So it makes it easier to understand, I believe. ;]
– rbz
Thank you, RBZ! It helped the hell!
– Lucas de Carvalho