-1

Following is my function to send mail using codeigniter. There is issue related to using link only, I have tested all other things. If I remove link or use of domain name mail goes to inbox.

public function send_notification()
{
     $body = "<div style='width:100%; margin:0 auto;'>
                        <table style='background-color:#ffffff;padding:0 10px; width:100%;box-shadow: 0px 0px 4px #263b91;'>
                            <tr>
                                <td style='text-align:center;'>
                                    <a href='https://example.com'><b>Click Here</b></a>
                                </td>
                            </tr>
                            <!-- mail body -->
                            <tr>
                                <td>
                                    <p style='width:100%;'>
                                        <h4>Message</h4>
                                    </p>
                                </td>
                            </tr>
                        </table>
                        <!-- footer -->
                        <table style='width:100%;background-color:#8dc440;box-shadow: 0px 2px 3px 0px #000;'>
                            <tr>
                                <td>
                                    <p style='font-size:14px; text-align:center;'>
                                        <small>&copy; 2017 All Rights Reserved</small>
                                    </p>
                                </td>
                            </tr>
                        </table>
                    </div>";            
        $subject = "Notification from Example";
        $config['protocol']     = $this->config->item('protocol'); // 'smtp'
        $config['smtp_host']    = $this->config->item('smtp_host'); //mail.example.com
        $config['smtp_port']    = $this->config->item('smtp_port'); //25
        $config['smtp_timeout'] = $this->config->item('smtp_timeout'); //7
        $config['smtp_user']    = $this->config->item('smtp_user'); info@example.com
        $config['smtp_pass']    = $this->config->item('smtp_pass');
        $config['charset']      = $this->config->item('charset'); utf-8
        $config['newline']      = $this->config->item('newline'); \n\r
        $config['mailtype']     = 'html'; // or text
        $config['validation']   = TRUE; // bool whether to validate email or not    
        $this->email->initialize($config);
        $this->email->from('info@example.com','Exaple');
        $this->email->to('prashant.hanamghar@gmail.com');
        $this->email->subject($subject);
        $this->email->message($body);
        $this->email->send();
}
  • You could use [a mail testing tool](https://www.mail-tester.com/) to check what problems there are and edit the result to your question. This will probably help a lot to get an answer. – D B Sep 06 '17 at 07:19

1 Answers1

0

There is no sure shot trick for this. Try to specify all types of headers.

ex:

  $headers .= "Reply-To: The Sender <sender@sender.com>\r\n"; 
  $headers .= "Return-Path: The Sender <sender@sender.com>\r\n"; 
  $headers .= "From: The Sender <senter@sender.com>\
  $headers .= "Organization: Sender Organization\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
  $headers .= "X-Priority: 3\r\n";
  $headers .= "X-Mailer: PHP". phpversion() ."\r\n" 

And also check for the 'SpamAssassin score'

SNG
  • 358
  • 4
  • 15
  • 1
    No, this is nonsense. Including these headers will not improve your mail deliverability. Some of them may actually make it worse -- for instance, some versions of SpamAssassin will be more likely to mark mail as spam if it contains the (bogus and practically unused) `X-Priority` header. –  Sep 06 '17 at 07:44
  • Thank you Sucharitha, But I don't have any problem with headers. Also I found the solution to use google shorten URLs. But it is not working in case I want to add image in my mail body. – Prashant Hanamghar Sep 06 '17 at 09:19
  • **Google Shorten URL** solved my problem. I used google short url to add image also. So now my mail is not going in spam for gmail also. – Prashant Hanamghar Sep 06 '17 at 10:54