php codeigniter电子邮件库

php codeigniter电子邮件库

问题描述:

i'm having a trouble here. why can't i send email using smtp? the error looks like this. email bug

the code looks like this

   $config = Array(
                    'protocol' => 'smtp',
                    'smtp_host' => 'mail.email.com',
                    'smtp_port' => 25,
                    'smtp_user' => 'admin@email.com',
                    'smtp_pass' => 'pass'
                    );
            $this->email->initialize($config);
            $this->email->cc('admin@provider.net');
            $this->email->set_mailtype('html');
            $this->email->from('admin@provider.net', 'Admin');

$this->email->send();
if(!$this->email->send())
{
    show_error($this->email->print_debugger());
}

code update:

$this->load->library('email');
$config = Array(
                      'protocol' => 'smtp',
                      'smtp_host' => 'ssl://smtp.googlemail.com',
                      'smtp_port' => 465,
                      'smtp_user' => 'account@gmail.com',
                      'smtp_pass' => 'password',
                      'smtp_timeout' => '4',
                      'mailtype'  => 'html', 
                      'charset'   => 'iso-8859-1'
                );
                $this->email->initialize($config);
                $this->email->set_newline("
");
                //$this->email->set_mailtype('html');
                $this->email->cc('admin@email.co.id');
                $this->email->from('admin@email.co.id', 'Admin');
                $this->email->to('email@email.com');
                $this->email->subject('test online');
                $this->email->message('test email');
                if(!$this->email->send())
                {
                    echo $this->email->print_debugger();
                }
                else
                {
                    echo 'sent';
                }

and it returned this message.

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

Fixed! the problem was not the openSSL or the script, the problem was SELinux forbid httpd to send mail and the solution was setsebool httpd_can_sendmail on

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

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'admin@email.com';
$config['smtp_pass'] = 'pass';

$this->email->initialize($config);
            $this->email->cc('admin@provider.net');
            $this->email->set_mailtype('html');
            $this->email->from('admin@provider.net', 'Admin');

$this->email->send();
if(!$this->email->send())
{
    show_error($this->email->print_debugger());
}

try this....may this help....

Try to put the smtp_port parameter '465' in quotes and change the from to the same address as the account you are using to send the mail.