0

I am trying to send mail through gmail smtp relay. I used a gmail mail id and created app password after enabling 2-step verification. The function I used to send mail is as below:

function sendemail($name,$emailid,$token,$pwd, $type)
    {
        $config = array();
        $config['protocol']  = 'mail';
        $config['mailpath']  = '/usr/sbin/sendmail';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_user'] = 'eticketing.info.cdit@gmail.com';
        $config['smtp_pass'] = 'MYGMAILAPPPASSWORD';
        $config['smtp_port'] = 587;
       
        $config['smtp_crypto']  = 'ssl';
        $config['smtp_timeout'] = 600;
        $config['mailtype']     = "html";
        $config['charset']      = "utf-8";
        $config['newline']      = "\r\n";
        $config['wordwrap']     = TRUE;
        $config['validate']     = FALSE;
        
        $email = \Config\Services::email();
        
        $email->initialize($config);
        $email->setFrom('eticketing.info.cdit@gmail.com', 'e-Ticketing: Complaints & Feedback Management System CDIT');
        $email->setTo($emailid);

        if ($type == 'verify') {
            $email->setSubject('Password for E-Ticketing Login');
            $email->setMessage('Dear '.$name.',Your credentials for e-ticketing Login is<br/> Username: '.
                $emailid.'<br/>Password: '.$pwd.'<br/>
            Application URL: <a href="'.base_url().'">'.base_url().'</a>');

        } 
        elseif(($type == 'forgot')||($type == 'reset')){
          $email->setSubject('Password Reset for E-Ticketing Login');
          $email->setMessage('Dear '.$name.',Your new credentials for e-ticketing Login is<br/> Username: '.$emailid.'<br/>Password: '.$pwd.'<br/>
          Application URL: <a href="'.base_url().'">'.base_url().'</a>');
        }

        if ($email->send()) {
            return true;
        } else {
            /*echo "<p>Email NOT Send</p>";
            echo $this->email->print_debugger();
            die;*/
            return false;
        }
    }

The function returns true but the email is not found in the recipient inbox. No error is found in the gmail inbox or codeigniter side. What more settings should I do in the GMail to get the email send correctly

tanzeem
  • 161
  • 1
  • 3
  • 8

1 Answers1

0

you should decide what protocol use to send the email to:

  • mail - using PHP to send email
  • sendmail - using server application to send email(if installed in your server (mailpath:/usr/sbin/sendmail))
  • smtp - use an smtp server to send email (local or remote smtp servers)

you need to use smtp protocol Sending email with gmail smtp with codeigniter email library

neurodede
  • 100
  • 6