简体   繁体   中英

sending email using codeigniter email class

i have an error by trying to send an email using codeigniter email Class.

I have an error of : Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

How can i test to send email in codeigniter?. I am also using localhost. Is this problem only occurs when i use localhost?

Here is my code:

public function emailme() {
        $this->load->library('email');
        $message = $this->input->post('email_msg');
        $this->email->from('iamjohnx3303@yahoo.com', 'John');
        $this->email->to('iamjohnx3302@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message($message);
        $this->email->send();
    }

Configuration in sendmail.ini

path c:\\xampp\\sendmail\\sendmail.ini

Configurations

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com

in php.ini

path c:\\xampp\\xampp\\php\\php.ini

[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

then

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype'  => 'html', 
'charset'   => 'iso-8859-1'
 'wordwrap' => TRUE
);

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

Mail Settings in XAMPP(Important)

$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail

$this->email->subject('testing');
$this->email->message($message);

$this->email->send(); //sending mail

Use this before your send mail script

// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM