Reputation:
I am trying to send an activation email from my website to the user. No matter what I do, the email is going straight to the junk folder.
I have logged into my cPanel, gone to E-Mail Authentication and enabled Domain Keys and SPF, but to no avail.
It's also worth mentioning that I'm using PHPMailer class with the default mail() type. I tried using sendmail, but it was unable to execute (shared host), and I tried SMTP, but I don't have the details for that (as far as I know).
Is there anything else I need to do?
Here is the code that is sending the email for your reference.
if (isset($_SESSION['registered'])) {
require_once '/home/wwwmcser/public_html/inc/vendor/class.phpmailer.php';
//mail
$mail = new PHPMailer;
$mail->SetFrom('[email protected]','MCSR Team');
$mail->AddReplyTo('[email protected]','No Reply');
$mail->AddAddress($_SESSION['userEmail'],$_SESSION['userName']);
$mail->Subject = 'Verify your account || MCServerRanks';
$mail->Body = "removed";
$mail->AltBody = "removed";
if (!$mail->Send()) {
$_SESSION['mailErr'] = 'There was an error sending your mail. This has been reported. Please contact support for assistance.';
error_log('Mailer Error: ' . $mail->ErrorInfo);
}
unset($_SESSION['userEmail']);unset($_SESSION['userName']);unset($_SESSION['activateHash']);
//show page
//rest of page is shown below, but I've removed that
Upvotes: 3
Views: 10785
Reputation: 78
This is happening due to the irregularities with in the Host address and From Address which You are sending the mail. If both these address doesn't belongs to same server then the mailing app will detect that mail as spam or junk.
$mail->Host='mail.developerbaijan.com';
$mail->Username='[email protected]';
This will obviously resulting in junk mail due to the irregularity in host and user. If the from address is so may also end up the mail in the same.
You Should try like this
$mail->Host='mail.google.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='[email protected]';
$mail->Password='*********';
$mail->setFrom('[email protected]','name');
Upvotes: 4
Reputation: 10161
Make sure the SPF records are added to the DNS TXT record. SPF record is relative to the domain you use for expedition So if you want to send an E-mail as [email protected] from IP address 192.168.3.4 you need to create (if you are not the admin of foo.bar) a DNS TXT record/s for foo.bar as such
v=spf1 +ip4:192.168.3.4 -all
This tells the remote server that the foo.bar domain sends legitimate email from 192.168.3.4 and that all other sources are only pretending to be foo.bar.
Note that the IP can be either ip4 or ip6.
Also you can add Subnets, FQDN names, MX records, or include SPF records from other domains, use a single SPF record per domain with as many items as needed
Upvotes: 1
Reputation: 15
Set your address as being their address in the automated e-mail so they receive an e-mail from what appears to be their own email with a "authentication required .. success" etc as title - this will prevent junk problem but may confuse some clients unless specified on site
Upvotes: 0