Viewed   72 times

Here are my codes for sending mail:

    $fullname = $_POST['fullname'];
    $email = $_POST['email'];
    $telephone = $_POST['telephone'];
    $email = $_POST['email'];
    $date = $_POST['date'];
    $time = $_POST['time'];
    $adult = $_POST['adult'];
    $children = $_POST['children'];
    $company_name = $_POST['company_name'];
    $addition = $_POST['addition'];
    $confirm = $_POST['confirm'];

    $body = '
    <table width="100%" border="0" cellpadding="0">
        <td>Dear Sir,
        <td><b>Booking request from '.$fullname .'</b><br /><br />
          <u>The details provided are:</u><br />
          <p>Name : '.$fullname.'<br />
          E-mail Address: '.$email.'<br />
          Telephone: '.$telephone.'<br />
          Date: '.$date.'<br />
          Time: '.$time.'<br />
          Adult: '.$adult.'<br />
          Children: '.$children.'<br />
          Company Name: '.$company_name.'<br />
           Confirm by: '.$confirm .'<br />
         Additional Requirements: '.$addition.'<br />
        <p>Thank you,<br />
        Kaavya Cuisine

    $to         = '';
    $subject    = 'Booking Request';
    $sitename='Website Name';

    $mail = new PHPMailer(); 

    $mail->AddAddress($to, $sitename);
    $mail->Subject    = $subject;


Every time I send the mail, it goes in to spam. Does anyone know why this is happening?



Based on you code i notice that you are sending an email directly from you web page on your domain.

For example you used an address.

When the recipient receive the emails the mail service of the recipient may test a reverse DNS of the sender of the mail. So the sender is from but the mail comes from your domain which of course is not

So I receive a mail from an address but the IP sender isn't related at all with domain that's SPAM!

I think a possible solution is: in you PHP code use authenticate with SMTP and from there send the mail!

Tuesday, November 1, 2022

Solution: Use Mailgun (not tested) or Sendgrid (tested and works wonders!). There is a price-difference between the two, - but in short: Mailgun is good if you're small; Sendgrid is good if you're big.

Either that, - or send mails using MailChimps API or something. It's can't be fixed on shared hosts (most likely). The reason is below.

Explanation: I've later learned more about how shared hosts work. Imagine that several different sites are located on the same server (such as, and That means that if sends a bunch of crap-emails, then Gmail (and other spam-filters) mark that IP-address as spam. So if then send out stuff, then that'll (probably) come from the some IP-address and therefore end up in spam. Shared hosts can't really do anything about it (and don't care, since so few people have this problem). And that is why it's so cheap.

Sendgrid and Mailguns IP-addresses are marked as 'fine' by all the spam-filters, and that's the service that you're paying for with them. They keep it that way, by monitoring how many emails you send out are being marked as 'spam'. If it's something like 5%-10% or something crazy low, then Sendgrid/Mailgun will block your account until you fix it (going through a long process, where you have to contact their customer service and do 1.000 hail-Mary's and all kinds of wierd stuff).

I heard that if you get your own server (which is way more expensive), and set up your own mail-server, then you have to be really careful, not to be marked as spam. Cause spam-filter are really tough nowadays...

Friday, December 23, 2022

After trying various ways, i found following code working with almost all email providers

$to['email'] = "recipients email address";      
$to['name'] = "name";   
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = '';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('', 'any name'); 
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;    
$mail->Subject = $subject;
$mail->Body    = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;                        


variable values needs to be changed accordingly. Hope these helps people having issues with PHPmailer

Saturday, November 19, 2022

The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

Saturday, December 24, 2022

Your vps doesn't have rDNS configured and the HELO points to a different ip. inconsistencies in HELO and missing rDNS trigger many spamfilters.

Received: from ([])

Host not found: 3(NXDOMAIN) has address

Set a HELO Hostname whose A-Record points back to your VPS and configure the rDNS (PTR) to the same hostname.


  • Create a new A-Record ''
  • Set the HELO to ''
  • Set the reverse DNS (PTR) for to

Also your senderdomains have somewhat strange "TXT" records:

dig txt +short 
dig txt +short

you may want to change these into correctly formatted SPF records, eg.

v=spf1 ip4: ip4: ~all
Friday, August 19, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :