Is not receiving email in codeigniter - codeigniter

I cant receive any email but my if statements says that an email was successfully sent, please help, here is my controller
public function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '****', //email
'smtp_pass' => '****' //password
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('//email', '//name');
$this->email->to('//recipient');
$this->email->subject('This is a test email');
$this->email->message('Hi, This is a test email. Please advise!');
if($this->email->send())
{
echo 'Your email was successfully sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
btw i tested it by using localhost/email/index.php/email/index

Your mail sending part is correct. No issues with that.
If you are trying this in local you have to edit you mail setting in php.ini and sendmail.ini.
Or else upload it to live server into new folder name demo(Not root). so you can test it easily.

Related

How to send a mail using gmail smtp in codeigniter

I want to send an email from my Gmail account through the website. how do I do that? I've tried every possible way but couldn't get the desired output.
public function mailuser(){
$config = Array(protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com','smtp_port' => 465,'smtp_user' => 'xxxx#gmail.com','smtp_pass' => 'xxxx','mailtype' => 'html');
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
if($this->email->send()){
echo 'Success email Sent';
echo $this->email->print_debugger();
}
else{
echo 'Email Failed To Send';
echo $this->email->print_debugger();
}
}
I think you are using wrong parameters in config like ssmtp
protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com'
Your config array should look like :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
$result = $this->email->send();
Also verify to enable extension extension=php_openssl.dll in php.ini.
if not please remove ;

Mail function is working only once at a time : Codeigniter

I am using Codeigniter email library to send emails. I have integrated email settings like this in my model
public function savedetails($data) {
$firstmail = $this->sendmail(1, $data);
$secondmail = $this->sendmail(2, $data);
}
public function sendmail($flag, $data) {
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => $this->config->item('emailhost'),
'smtp_user' => $this->config->item('emailusername'),
'smtp_pass' => $this->config->item('emailpassword'),
'smtp_port' => 25,
'smtp_crypto' => 'tls',
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
if($flag == 1) {
$this->email->from('someone#example.com', 'Someone');
$this->email->to('someone#example.com, 'Someone');
$this->email->subject('This is a test message');
$message = $this->load->view('email/firstmail.php', $data, true);
} else {
$this->email->from('someone#example.com', 'someone');
$this->email->to('someone#example.com', 'someone');
$this->email->subject('This is a test message');
$message = $this->load->view('email/secondmail.php', $data, true);
}
$this->email->message($message);
return $this->email->send();
}
So first email goes successfully but the second email fails everytime. Second email is not going delivered and giving false each time but first email delivered successfully. What is the issue here ? How can i get second email delivered successfully too in Codeigniter ?

Send email by codeigniter

I am using codeigniter to send email.
function forget_pw() {
$this->load->library('email');
$config['smtp_host'] = 'host address';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$this->email->initialize($config);
$this->email->from('admin#email.com', 'Admin');
$this->email->to('test#yahoo.com.hk');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
No any error show in console. But the email didn't send out.
You can create a function like this:
public function sendEmail($subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'xxxxx.xxxxxx.xxxxx',
'smtp_port' => 465,
'smtp_user' => 'xxxxx.xxxxxx.xxxxx',
'smtp_pass' => 'xxxxx.xxxxxx.xxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxxx.xxxxxx.xxxxx');
$this->email->to('xxxxx.xxxxxx.xxxxx');
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
And use it like this $this->sendEmail('Title', 'Message'); Good luck

sending mail using codeigniter

This is my send email function
public function send_requs_mail()
{
$this->load->library('email');
$config=array(
'protocol' => 'smtp',
'smtp_host' =>'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxxx#gmail.com',
'smtp_pass' => 'yyyyyy'
);
$this->email->set_newline("\r\n");
$this->email->initialize($config);
$this->email->from($this->input->post('from'), 'iftekhar');
$this->email->to($this->input->post('to'));
$this->email->subject('Email Test');
$this->email->message($this->input->post('message'));
if($this->email->send())
{
echo'your email was sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Now when I press Send button I get successful message I mean I get message "your email was sent" but in email Inbox I didn't get any message.
check if $this->input->post('from') and $this->input->post('to') return valid email addresses, otherwise it will not send the email!
use this $config Array
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_crypto' => 'ssl',
'smtp_user' => 'your mail',
'smtp_pass' => 'your password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
And to install SSL
First see if there is open-ssl extension in your php.ini file if not then put the below code in the ini file in extension part.
extension=php_openssl.dll
Restart the Apache service.

Contact from in codeigniter without using gmail user and password

I used the following code in controller of my contact form.
public function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email#mydomain.com',
'smtp_pass' => 'myPassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
Can i send the email without using "smtp_user" and "smtp_pass"?
Just use mailprotocol in the config.
See the docs: http://ellislab.com/codeigniter/user-guide/libraries/email.html
You can use the default config and send email like:
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();

Resources