0
public function send_mail()
{
    $this->CI->load->library('email');
    $config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtpauth.net4india.com',
        'smtp_port' => 587,
        'smtp_user' => 'xxxxx@my_domain.in',
        'smtp_pass' => 'xxxxxxxx',
        'newline'   => '\r\n',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );
    $this->CI->email->initialize($config);
    $this->CI->email->set_mailtype("html");
    $this->CI->email->set_newline("\r\n");
    $this->CI->email->from('info@my_domain.in', 'My Domain');
    $this->CI->email->to('xxxx@gmail.com');
    $this->CI->email->subject("Test Subject");
    $this->CI->email->message('Test Content');
    if(!$this->CI->email->send())
    {
        $error = $this->CI->email->print_debugger();
        echo "<pre>"; print_r($error); echo "</pre>"; exit;
        return false;
    }
    return true;
}

I have my domain and email registered to net4india.com, and hosting at godaddy.

Using the above code i'm able to send mail from my localhost but not able to send from godaddy server.

I have added mx records in godaddy hosting. Changed the routing to remote manager.

I did lots of googling still ends up with no solution.

Satish51
  • 119
  • 6
  • [Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method](https://stackoverflow.com/questions/45252547/unable-to-send-email-using-php-smtp-your-server-might-not-be-configured-to-send?rq=1) – Md Musfekur Rahman Feb 03 '19 at 08:28
  • [Unable to send email using PHP mail(). Your server might not be configured to send mail using this method](https://stackoverflow.com/questions/50186498/unable-to-send-email-using-php-mail-your-server-might-not-be-configured-to-se) – Md Musfekur Rahman Feb 03 '19 at 08:32
  • Did You try Port 465 – ivion Feb 03 '19 at 08:35
  • yes i tried but it dint worked – Satish51 Feb 03 '19 at 08:38
  • try to add ssl to server: `'smtp_host' => 'ssl://smtpauth.net4india.com',` – ivion Feb 03 '19 at 09:39
  • yes i tried that earlier. Thanks for your response. I got the solution. :-D – Satish51 Feb 03 '19 at 09:47

2 Answers2

0

After doing lots of r&d i end up finding Sending mail through other providers isn't allowed on godaddy

public function send_mail()
{
    $this->CI->load->library('email');
    $config = array(
            'protocol'  => 'mail',
            '_smtp_auth' => FALSE,
            'smtp_host' => 'localhost',
            'smtp_port' => 25,
            'newline'   => '\r\n',
            'mailtype'  => 'html',
            'charset'   => 'utf-8'
        );
     $this->CI->email->initialize($config);
    $this->CI->email->set_mailtype("html");
    $this->CI->email->set_newline("\r\n");
    $this->CI->email->from('info@my_domain.in', 'My Domain');
    $this->CI->email->to('xxxx@gmail.com');
    $this->CI->email->subject("Test Subject");
    $this->CI->email->message('Test Content');
    if(!$this->CI->email->send())
    {
        $error = $this->CI->email->print_debugger();
        echo "<pre>"; print_r($error); echo "</pre>"; exit;
        return false;
    }
    return true;
}

old config:

$config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtpauth.net4india.com',
        'smtp_port' => 587,
        'smtp_user' => 'xxxxx@my_domain.in',
        'smtp_pass' => 'xxxxxxxx',
        'newline'   => '\r\n',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );

new config:

$config = array(
            'protocol'  => 'mail',
            '_smtp_auth' => FALSE,
            'smtp_host' => 'localhost',
            'smtp_port' => 25,
            'newline'   => '\r\n',
            'mailtype'  => 'html',
            'charset'   => 'utf-8'
        );

I end up setting the _smtp_Auth to false, and using there server to send mails.

I even removed my username and password as i made the authentication to false.

changing port number to 25 as mentioned by godaddy.

Satish51
  • 119
  • 6
0

This working solution for Codeigniter 3.x

Create email.php file in config folder this will auto load email configuration

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$config['useragent'] = 'Codeigniter';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://mail.domain.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'noreply@domain.com';
$config['smtp_pass'] = 'Password@123';
$config['charset'] = 'utf-8';
$config['newline'] = '\r\n';
$config['mailtype'] = 'html';
$config['validation'] = TRUE; 

In your controller use

$html = '<p>Hello</p>';
$html .= '<p>This is some demo email text.</p>';

                $this->load->library('email');
                $this->email->from('noreply@example.com', 'Label', 'returnpath@example.com');
                $this->email->to('recipient@example.com');
                $this->email->bcc('cc@example,com', 'anothercc@example.com');
                $this->email->subject('Subject For Mail');    
                $this->email->message($html);
                $this->email->send();