How to Send Email from Localhost Using PHP on Linux

How to send email with codeigniter in linux localhost

there are 2 ways to test email on localhost one is mailcatcher you need to install mailcatcher on you development machine super simple smtp server, other is mailtrap i prefer mailtrap no need to install anything, create an account on mailtrap and you are ready to test your emails on localhost once you login you can get your account setting from mailtrap

$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "rn";

if(ENVIRONMENT == 'development'){

$dev_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.mailtrap.io',
'smtp_port' => 2525,
'smtp_user' => 'smtp_user_from_your_mailtrap',
'smtp_pass' => 'smtp_pass_from_your_mailtrap',
'crlf' => "\r\n",
'newline' => "\r\n"
);

$config = array_merge($config, $dev_config);

}
$this->email->initialize($config);

and happy local email testing.

PHP : send mail in localhost

It is configured to use localhost:25 for the mail server.

The error message says that it can't connect to localhost:25.

Therefore you have two options:

  1. Install / Properly configure an SMTP server on localhost port 25
  2. Change the configuration to point to some other SMTP server that you can connect to


Related Topics



Leave a reply



Submit