2

When i try to send a mail with PHPmailer via gmail smtp server the mail will be flagged as spam. i am using a hotmail account to receive the email.

i've looked to other topics about this problem but they mention that they set the "from" to their own domain name but for me [email protected] is good enough.

this is the code i use:

$mail             = new PHPMailer();
$body             = "test";
$mail->IsSMTP();
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = "ssl";  
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;                  
$mail->Username   = "[email protected]"; 
$mail->Password   = "mypassword";            
$mail->SetFrom('[email protected]', 'myaccount');
$mail->Subject    = "Test subject";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "test"); 
$mail->Send()

I've read this topic: How do you make sure email you send programmatically is not automatically marked as spam?

but like i said i don't need my own domain name. Or is this impossible and do i need to use my own domain and use SPF and DKIM?

Edit:

I've tested sending emails to yahoo and gmail and both work only hotmail will mark them as spam.

Solved:

I tried to send a mail with the gmail webclient and even then my mail gets flagged as spam. Somehow the gmail smtp servers are blacklisted. So i created an hotmail account and changed the code to use hotmail smpt server.

$mail->SMTPSecure = "tls";              
$mail->Host       = 'smtp.live.com';  
$mail->Port       = 587; 

Now my mails are not marked as spam anymore on yahoo gmail and hotmail.

Stan
  • 629
  • 7
  • 18
  • Yes! I am sorry. Best luck! – statosdotcom Feb 17 '19 at 16:02
  • Look at the headers of a message you have received in hotmail - it will often say *why* a message has been marked as spam, such as for SPF or DKIM failure, though since you're sending from gmail using a gmail address, both of those should pass without you doing anything. – Synchro Feb 17 '19 at 17:30
  • Authentication-Results: spf=pass (sender IP is 209.85.208.66) smtp.mailfrom=gmail.com; hotmail.com; dkim=pass (signature was verified) header.d=gmail.com;hotmail.com; dmarc=pass action=none header.from=gmail.com; Received-SPF: Pass (protection.outlook.com: domain of gmail.com designates 209.85.208.66 as permitted sender) receiver=protection.outlook.com; client-ip=209.85.208.66; helo=mail-ed1-f66.google.com; Received: from mail-ed1-f66.google.com (209.85.208.66) by CO1NAM05FT062.mail.protection.outlook.com (10.152.96.180) with Microsoft SMTP Server – Stan Feb 17 '19 at 17:52
  • i also use a custom domain in zoho, but ended up the same flagged output inside the receiver *gmail* no luck then. @Stan – gumuruh Mar 08 '22 at 08:03
  • i have the same problem ... not luck with it i have not solved it ... XD –  Dec 08 '22 at 19:01
  • You can also try to set the name of the sender to the email adres you are sending with (second parameter in the SetFrom() function) i noticed when doing this the email has more chance of being accepted. – Stan Dec 09 '22 at 21:29

0 Answers0