Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Everytime my mail goes to spam in phpmailer

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">
      <tr>
        <td>Dear Sir,
        </td>
      </tr>
      <tr>
        <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>
           </td>
      </tr>
      <tr>
        <td>
        <p>Thank you,<br />
        Kaavya Cuisine
        </p></td>
      </tr>
    </table>
    ';

    $to         = '[email protected]';
    $subject    = 'Booking Request';
    $sitename='Website Name';

    $mail = new PHPMailer(); 
    $mail->AddReplyTo($to,$sitename);
    $mail->SetFrom($email,$fullname);


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

    $mail->MsgHTML($body);
    $mail->Send();

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

like image 618
sujal Avatar asked Apr 03 '12 06:04

sujal


People also ask

How do I stop emails going to spam in PHPMailer?

Make sure that the domain you send mails from are using the same IP address as when you do a reverse lookup of that IP address, best to use a subdomain like “mail” for this particular use case. example: mail.mydomain.com with IP 123.123. 123.123 and in a reverse lookup 123.123.

How many emails can I send with PHPMailer?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *. secureserver. * ).

Why does SMTP mail go to spam?

Sometimes WordPress emails go to spam even after you've set up WP Mail SMTP. This is almost always caused by incorrect DNS settings at your domain. Your email provider may need you to set up SPF, DMARC, and DKIM records to authenticate your WordPress emails.

Does PHPMailer have a limit?

PHPmailer is just a piece of PHP code, and there are no limits on how often a particular piece of PHP code can be executed on a website. The only limits on PHPmailer are the limits of whatever email backend you're using.


2 Answers

Normally, an email is marked spam if its "From:" header value's domain part does not match the domain that is actually sending the email.

The easiest way to bypass this is to use a "From:" that matches your domain, and use a "Reply-To:" header to the email that you set in "From:" header

For eg: if you are sending mail from mydomain.com and your from email is [email protected], you should change your headers to this:

From: [email protected]

Reply-To: [email protected]

like image 145
mim Avatar answered Oct 08 '22 10:10

mim


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 @hotmail.com 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 @hotmail.com but the mail comes from your domain which of course is not hotmail.com.

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

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

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

like image 26
ab_dev86 Avatar answered Oct 08 '22 11:10

ab_dev86