$mail = new PHPMailer(true);
try {
//Server settings
$mail->AddReplyTo('[email protected]','Post');
$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = '[email protected]';
$mail->Password = 'loginPassword';
$mail->Port = 465;
$mail->isHTML(true);
$mail->setFrom('[email protected],'Name');
$mail->addAddress('[email protected]', 'Name');
//Content
$mail->isHTML(true);
$mail->Subject = $mailSub;
$mail->Body = $mailMsg;
$mail->AltBody = $mailMsgAlt;
$mail->send();
echo "Mail sent!;
}catch (Exception $e){
echo "Mail not sent! Try again.";
}
This is how my code looks like, ofc the $mailSub, $mailMsg, $mailMsgAlt variables are defined! Can you help me please, I can't find why the mails always go to the spam folder.
The mail is put into spam folder by the recipient mail handler and it doesn't depend on the sender ( but actually it does and we'll look at it ).
A mail is marked as spam depending on the previous feedback from other mass users or same user. But internally, if the mail is not sent through a trusted mail redirector, with proper certification and encryption, it will be marked as spam.
A trusted mail redirector is who authenticates the email id of the sender, as the receiver can't do it. In this case, we can use whatever from
address we want, but the mail redirector won't check whether we actually own that email id. So it is not a trusted mail redirector.
For example, if you are using Gmail API for sending an email, you will have a unique API key to prove that you are the owner of the from
address you use. If the API key is wrong, you will get an error and the email won't be sent. That way, spam emails are prevented.