In my local environment the email works, but once I transfer to my online website, the smtp email does not work and shows timeout error.
This is my config/email.php file:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '[email]';
$config['smtp_pass'] = '[password]';
$config['smtp_timeout'] = 30;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
I use Cpanel, do I need to configure something?
smtp_host should change
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = $sender_email;
$config['smtp_pass'] = $sender_password;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->load->library('email', $config);
Related
I have a system that uses different emails for different parts of the system. I've got my config setup with a No-Reply email. However, if I try and send an email using different SMTP settings, it will try and use the Email config settings rather than the array settings I've specified.
These are the settings that are in my Email config file
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
Below is the list of settings I have specified in the array (These are the settings that I want to send this particular email through Gmail rather than Office365)
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
Is there any way to send emails via different SMTP settings rather than the ones specified in the Email config file? I have tried to send this email via the Gmail settings but it always appears to try and send through the Email config settings.
SOLUTION:
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'REMOVED';
$config['smtp_pass'] = 'REMOVED';
$config['smtp_port'] = '587';
$config['mailtype'] = 'html';
$config['charset'] = 'utf8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = '120';
$config['smtp_crypto'] = 'tls';
$this->email->initialize($config);
Fixed my issue and now I am able to send an email through an Ad-Hoc Gmail account rather than the Office365 one.
You can override the configuration in the config/Email.php (office365 in your case) file with a specific one (gmail, in your case) by building the $config array in the controller and then use it to initialize the email library with:
$this->email->initialize($config);
For this to work you must initialize the library using the overriding $config before actually doing anything else that requires the class, or the default settings will be used automatically
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'] = '';
}
I have tried the code below and keep getting this error
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.keytimeng.com'; //change this
$config['smtp_port'] = '25';
$config['smtp_user'] = 'info#keytimeng.com'; //change this
$config['smtp_pass'] = 'xxxx'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->email->initialize($config);
$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();
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.tch-pnt.in"; //
$config['smtp_port'] = 587;
$config['smtp_user'] = "bnft#tch-pnt.in";
$config['smtp_pass'] = "********";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
Error...
I am using above configuration setup for sending email...
No error but i am not getting mails in my inbox.I tried 3 times.
I used default port as 25 still no mails
I think you should try
$config['smtp_host'] = "sslv2://smtp.tch-pnt.in";
or try port number 465.