1

I'm working with Codeigniter in CPanel and my code already sends a mail, but when it gets to the receiver, the hostname is shown on the sender. I tried some answer to questions as : Change the sender name php mail instead of sitename@hostname.com but in Codeigniter, they don't work.

This is my code:

 $config = Array(
                'protocol' => 'ssmtp',
                'smtp_host' => 'ssl://ssmtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => 'mail@domainiwant.com', 
                'smtp_pass' => 'password',            
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1',
                'useragent' => 'MY NAME',
            );
            $this->load->library('email', $config); 
            $this->email->set_newline("\r\n");
            $this->email->from('mail@domainiwant.com', 'MY NAME');

            $email_to = 'receiver@gmail.com';
            $this->email->to($email_to);

            $this->email->message('Message testing ...');
            $this->email->send();

However, as I said, when the mail gets to the receiver, they appear with the hostname and a completely different mail address like the one I put on $config

I know this only sets the envelope sender but I want to set the mail address to be mail@domainiwant.com instead of receiving the mail with somemail@host.com.ex

Sergio Laureano
  • 185
  • 2
  • 10
  • Do you have an SMTP server?? Please ask for it from service provider. – BEingprabhU Feb 29 '20 at 17:08
  • According to CI's own documentation, `$config['protocol']` should be set to `smtp`, not `ssmtp`. Since `ssmtp` is not an accepted value in the config, your code may be defaulting to the `mail` setting, which will attempt to deliver the mail using your own server as the sender instead of using your SMTP settings. Give it a try and let me know – Javier Larroulet Feb 29 '20 at 19:17

1 Answers1

1

According to the documentation of CodeIgniter's email library available HERE, your whole problem is a simple typo.

$config['protocol'] allows mail, sendmail and smtp as values. If you don't set the variable, or use a value which is not allowed, the whole library defaults to mail which attempts to use your own server as the mail gateway (which explains why your sender address shows as username@servername)

Change the protocol from ssmtp to smtp so that you actually use the Google SMTP server you intend to use and you'll get the results you expect

Javier Larroulet
  • 3,047
  • 3
  • 13
  • 30