Search code examples
phpcodeigniteremailgoogle-workspace

Gsuite account won't send emails codeigniter


I just set up google mx records for my domain. When i use my normal gmail account, emails are sent but when I use my gsuite account, the mails are not sent. I am hosting my site on siteground. However I can receive emails from other email accounts on my gsuite account.

$this->load->library('email');

    $subject = 'Subject';
    $message = 'My message';

    //configure email settings
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.gmail.com';
    $config['smtp_port'] = 465
    $config['smtp_user'] = 'info@mydomain.com';
    $config['smtp_pass'] = 'my_password';
    $config['mailtype'] = 'html';
    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['newline'] = "\r\n"; //use double quotes
    $config['validation'] = TRUE;
    $this->email->initialize($config);

    //send mail
    $this->email->from('info@mydomain.com', 'MyDomainName');
    $this->email->to($to_email);
    $this->email->subject($subject);
    $this->email->message($message);

    //echo json_encode($this->email->print_debugger());
    if($this->email->send())
    return true;
    else
        return false;       

Solution

  • You didn't attach any error message, but since it's working for your other Gmail accounts, try checking if turning on access to "less secure apps" for this account solves this issue and report back.

    https://myaccount.google.com/lesssecureapps (Don't forget to choose the right account, if you're logged in to several ones).