Welcome Guest, Not a member yet? Register   Sign In
send email in CI
#1

[eluser]lamhuy300890[/eluser]
I have problem with sending email in CI. I have upload my site to host (not local host).

The first code, no error, cannot send email.
Code:
$from = "[email protected]";
$to = "[email protected]";
$title = $this->input->post('title', TRUE);
$data_mail['name'] = $this->input->post('name', TRUE);
$data_mail['content'] = $this->input->post('content', TRUE);
$data_mail['date'] = date('d/m/Y');
    
$mail_content = $this->load->view('email/email_contact', $data_mail, true);
    
$opt="Content-type: text/html; charset=utf-8\\r\\nFrom: $from\\r\\nReply-to: $from";
mail( $to, $title, $mail_content, $opt );


The second code, alot of error, fsockopen() ...
Code:
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'stmp.mysite.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = '123456';
$config['smtp_port'] = '25';
$config['smtp_timeout'] = '5';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';

$this->load->library('email', $config);  
$this->email->initialize($config);
  
$this->email->from($from);
$this->email->to($row_config->adminEmail);
$this->email->subject($title);
$this->email->message($mail_content);
  
$success = $this->email->send();

How can i solve this problem ?
Thanks.
#2

[eluser]brian88[/eluser]
did you check the user guide for the email class already?
http://ellislab.com/codeigniter/user-gui...email.html
Cause this is what I use.
Code:
if( $this->input->post() ){

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

$this->email->from($this->input->('email'), $this->input->('name'));
$this->email->to('[email protected]');

$this->email->subject('Email Test');
$this->email->message($this->input->('message'));

$this->email->send();

}
#3

[eluser]NotDior[/eluser]
Have you tried taking the $config out of your library load?

I have something similar to what you are doing, but have less settings (not sending HTML FWIW).

Code:
$config['smtp_host'] = 'mail.myhost.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'MySuperSecretPassword!';

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

....
#4

[eluser]lamhuy300890[/eluser]
[quote author="brian88" date="1333480796"]did you check the user guide for the email class already?
http://ellislab.com/codeigniter/user-gui...email.html
Cause this is what I use.
Code:
if( $this->input->post() ){

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

$this->email->from($this->input->('email'), $this->input->('name'));
$this->email->to('[email protected]');

$this->email->subject('Email Test');
$this->email->message($this->input->('message'));

$this->email->send();

}
[/quote]

I have tried this one but it cannot send email.


My last hosting use this simple code, it work. Now i change to another hosting (VPS use CentOS, and DirectAdmin) and cannot send email.
Do i config the server to send email ?
Code:
$from = "[email protected]";
$to = "[email protected]";
$opt="Content-type: text/html; charset=utf-8\\r\\nFrom: $from\\r\\nReply-to: $from";
mail( $to,  "Hello", "Hello, this is email", $opt );
#5

[eluser]brian88[/eluser]
Should work with no matter what hosting you have.

Code:
echo $this->email->print_debugger();

put that at the bottom of my code and see what it spits out




Theme © iAndrew 2016 - Forum software by © MyBB