0

Email sending is not working after I have uploaded my source on Hosted Server , my code is given below:

function sendMail($code,$email)
    {
        $config = Array(        
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_port' => 465,
            'smtp_user' => 'something@gmail.com',
            'smtp_pass' => 'something',
            'smtp_timeout' => '4',
            'mailtype'  => 'text', 
            'charset'   => 'utf-8'//'iso-8859-1'
        );

        $message = 'Your Verification code is :'.$code;
        $this->load->library('email',$config);
        $this->email->set_newline("\r\n");
        $this->email->from('isecvr@gmail.com',"iSec Community"); // change it to yours
        $this->email->to($email);// change it to yours
        $this->email->subject('Activate your account');
        $this->email->message($message);
        if($this->email->send())
        {
            return true;
        }
        else
        {
         show_error($this->email->print_debugger());
            return false;
        }

    }

My Attempts to make this work , some worked but they are sent to Spam not on inbox, and some does not work at all:

1 - changing 'protocol' => 'sendmail' [FAILED]

2 - changing 'smtp_host' => 'smtp.gmail.com' or 'smtp_host' => 'ssl://smtp.gmail.com' or 'smtp_host' => 'ssl://smtp.googlemail.com' or 'smtp_host' => 'smtp.googlemail.com' all [FAILED]

3 - changing 'smtp_port' => 587 or 'smtp_port' => 25 [FAILED]

4 - In my google email i have allowed Less Secure Apps , Disabled 2 Step Verification [FAILED]

5 - Commenting/removing $config variable [SUCCESS] but email is sent to SPAMS with following warning with yellow background This message may not have been sent by: isecvr@gmail.com

Kindly Suggest me what should i do , i am trying to send email for now more than 10 hours now.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Zulqurnain Jutt
  • 1,083
  • 3
  • 15
  • 41

3 Answers3

0

May be your server is not allowed to communicate with gmail server? It could be one of the possibility. If this is not the case then what is the output of "show_error($this->email->print_debugger());"? You must be getting some output from this line.

d.coder
  • 1,988
  • 16
  • 23
0

Sending email from Localhost :

1.If you will send email from localhost SMTP i.e commenting $config array, your messages will always be redirected to Spam unless

You have configured your server as mail server (With Postfix/Sendmail installed properly and configured with MX, SPF and DKIM records in DNS zone for your domain).

2. If you are using Gmail SMTP as relay for sending emails:

See : Sending email with gmail smtp with codeigniter email library

Just make sure that port 465 or 587 are open in firewall configuration.

Note: In my personal opinion , this is not a good practice and always has certain limitations. for eg : From address will always be the one used in as username SMTP configuration.

I would recommend setup and try free 3rd party SMTP services such as SparkPost, Sendgrid and mandrill and use them in your code.

Community
  • 1
  • 1
Sachin Singh
  • 113
  • 1
  • 7
0

The problem is very simple

  1. While working on submitting form via google the best practice it to callback direct smtp server, not ssl:// it will never work like that.

  2. Gmail uses TLS for sending mail with PORT 587 OR 465. It will never send mail via SSL using 465.

I have also figure it out that Authentication to TLS is not set.

Also make sure Under gmail account settings Access to Less Secure Apps is turned OFF, if it is on turn it off.

The answer i given on the basis of technical reasons.

Sachin G.
  • 528
  • 4
  • 9