I'm using codeigniter in my project, so what I'm trying to do is to send a simple email using the mail() php function, but nothing happend:
here is my controller (here I call the view email):
public function index()
{
$this->load->helper('url');
$this->load->view('email');
}
the view email contains:
<form action="<?php echo base_url() ?>email/blog_edit2" method="post" accept-charset="utf-8" enctype="multipart/form-data" >
<input type="submit" value="create">
</form>
I'm calling blog_edit2 the controller for send the email.
and the code of controller blog_edit2:
public function blog_edit2()
{
$this->load->helper('url');
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
$this->load->view("email");
}
I tested it in both localhost and a real host (free host) but nothing happen, what am I doing wrong? what do I need to configure? thanks
EDIT1: the controller blog_edit2 (using codeigniter email library):
public function blog_edit2()
{
$this->load->helper('url');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('[email protected]', 'myname');
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$result = $this->email->send();
$this->load->view("email");
}