codeigniter mail - i can send email but i can't received it - php

I am using this code to send email via localhost.
function send_email(){
date_default_timezone_set('Asia/Manila');
$ci =& get_instance();
$ci->load->library('email');
$config['protocol'] = "mail";
$config['smtp_host'] = "ssl://mail.smsgt.com";
$config['smtp_port'] = "25";
$config['smtp_user'] = "myemail#smsgt.com";
$config['smtp_pass'] = "";
$config['charset'] = "utf-8";
$config['mailtype'] = "text";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('sender#email.com', 'company email');
$ci->email->to('receiver#gmail.com');
$ci->email->subject('test subject');
$ci->email->message("testing email");
$check = $ci->email->send();
//echo $ci->email->print_debugger();
if ($check){
echo "true";
}else{
echo "false";
}
}
It always shows true but still I cant received it. What is problem with my codes? or is there something wrong?

**Your smtp and port is not working**
$config['smtp_host'] = "ssl://mail.smsgt.com";
$config['smtp_port'] = "25";
**Change into this**
$config['smtp_host'] = "ssl://smtp.mail.yahoo.com;ssl://smtp.gmail.com";
$config['smtp_port'] = 465;

Related

Error Sending Email using smtp.office365.com and PHP Codeigniter

Please help, send email error using SMTP Outlook 365.
previously it was still able to run, but suddenly an error.
these my code
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'XXX#XXXX.com';
$config['smtp_pass'] = '#########';
$config['smtp_port'] = '587';
$config['smtp_crypto'] = 'tls';
$config['starttls'] = FALSE;
$config['smtp_timeout'] = '5';
$config['wordwrap'] = TRUE;
$config['charset']='iso-8859-1';
$config['mailtype'] = 'html';
$config['newline']="\r\n";
$config['crlf']= "\r\n";
$this->email->initialize($config);
//Email content
$htmlContent = 'XXX';
$htmlContent .= 'XXX';
$this->email->to('XXX#XXXX.com');
$this->email->from('XXXXX#XXXXX.com','MyWebsite');
$this->email->subject('How to send email via SMTP server in CodeIgniter');
$this->email->message($htmlContent);
//Send email
$this->email->send();
if($this->email->send())
{
echo "Email sent!!";
} else {
echo "Email is not sent!!";
echo $this->email->print_debugger();
}
}
and these an error result

How to send mail from godaddy server using gmail account

Following is given the code, need help. I have the Goddady server, but I am not able to send mail.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['SMTP_Secure'] = 'ssl';
$config['smtp_server'] = 'relay-hosting.secureserver.net'; //smtp.gmail.com
$config['smtp_host'] = 'smtp.gmail.com'; //smtp.gmail.com
$config['smtp_port'] = '465'
$config['smtp_user'] = '....#gmail.com';
$config['smtp_pass'] = '******';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = true; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('....#gmail.com', 'sender_name');
$this->email->to('....#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.'); if($this->email->send())
{
echo "Working"; echo $this->email->print_debugger();}else{echo "Not working";
}

How to set the session time out for otp using codeigniter

I want to set the session time out for OTP,after set the time OTP will expire
Controlller code as shown in below
$six_digit_random_number = mt_rand(100000, 999999);
$this->session->set_userdata('otp', $six_digit_random_number);
$this->load->model('Login_model');
$pass['pass'] = $this->Login_model->forgot_pass_retrive($emailTo);
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'tworkreport#gmail.com';
$config['smtp_pass'] = '87xxxxxxxx';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text';
$config['validation'] = TRUE;
$this->email->initialize($config);
$this->email->from('tworkreport#gmail.com', 'Terasukhintrade');
$this->email->to($emailTo);
$this->email->subject('Reset your password');
$this->email->message('Click on link to reset your password '.$this->session->userdata['otp'] );
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('login',$data);
} else {
$this->session->set_flashdata('message', ' Email address not found!');
$this->load->view('login',$data);
}
}
}
you can use this to expire your OTP:
$this->session->set_tempdata('otp', $six_digit_random_number, 300);
Here 300 is seconds, which means your 'otp' session will expire after 5 minute.
For more information please refer https://www.codeigniter.com/user_guide/libraries/sessions.html .

Error Sending mail in code igniter

I'm trying to send an email with CodeIgniter, but this is what I get:
The following SMTP error was encountered: 110 Connection timed out
Unable to send email using PHP SMTP. Your server might not configured to send mail using this method.
Here is my code in email.php:
<?php
$CI =& get_instance();
if ($CI->config->item('installed') == true) {
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // Or "/usr/sbin/sendmail"
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['charset'] = strtoupper(get_option('smtp_email_charset'));
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['protocol'] = 'smtp';
$config['smtp_host'] = get_option('smtp_host');
$config['smtp_port'] = get_option('smtp_port');
$config['smtp_timeout'] = '30';
$config['smtp_user'] = get_option('smtp_email');
$config['smtp_pass'] = get_option('smtp_password');
// Set to "tls" if you need to use TLS
$config['smtp_crypto'] = '';
}

Codeigniter emailer not working

$this->load->library('email');
// set email data
$this->email->from($this->input->post('sender_email'), $this->input->post('sender_name'));
$this -> email -> set_mailtype("html");
$this->email->to('');
$this->email->reply_to($this->input->post('sender_email'), $this->input->post('sender_name'));
$this->email->subject('From: '.$this->input->post('sender_name'));
$this->email->message("<table><tr><td> </td><td>".$this->input->post('sender_name')."</td></tr><tr><td> </td><td>".$this->input->post('sender_email')."</td></tr><tr><td> </td><td>".$this->input->post('phone')."</td></tr><tr><td>Message: </td><td>".$this->input->post('message')."</td></tr></table>");
$this->email->send();
// create a view named "succes_view" and load it at the end
redirect('contact?email_succ=1');
exit();
This is the code I'm using to send email from a form in CI and it works only when I use SMTP login along with this.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'myemail#example.com';
$config['smtp_pass'] = 'emailpassword';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
Having this code right after loading the library solves the issue. But what's wrong with the default code that has been working all this time but suddenly stopped?
UPDATE: adding just this line $this->email->initialize($config); solves the issue, But why?.
Try the following code.
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->message = "Your Message";
$this->email->subject("Message Subject");
$this->email->from("user#gmail.com");
$this->email->to("admin#gmail.com");
$this->email->send();

Categories