I have a mail function. And when I start the service it send e-mail from my array. My array include 60 mail. When start the service it send 10-15 mail and after got error like this.
from: The following SMTP error was encountered:
Unable to send data: QUIT
quit:
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
function sendMail($to,$cc="",$subject,$message,$title="",$attach="",$from="")
{
$CI = & get_instance();
$CI->load->library("email");
$CI->email->clear(TRUE);
$CI->email->set_newline("\r\n");
if($title==""){
$title="q Group";
}
if($from=="") {
$from="q#q.com.tr";
}
$CI->email->from($from, $title);
if($cc<>"")
$CI->email->cc($cc);
$CI->email->subject($subject);
$CI->email->message($message);
if($attach<>"")
{
$CI->email->attach($attach);
}
$mailList = explode(",",$to);
$sendMailList = "";
foreach ($mailList as $key=>$item) {
if (filter_var($item, FILTER_VALIDATE_EMAIL)) {
$sendMailList .=$item.",";
}
else{
MailLogModel::setLog($item,$subject,0,"Mail Adresi Hatalı");
if(count($mailList)==1)
return ["status"=>false,"message"=>"Mail Adresi Hatalı"];
}
}
$sendMail = substr($sendMailList,0,-1);
$CI->email->to($sendMail);
if (! $CI->email->send()){
MailLogModel::setLog($sendMail,$subject,0,html_entity_decode(imap_utf8($CI->email->print_debugger('headers','subject'))));
return ["status"=>false,"message"=>$CI->email->print_debugger(array('headers'))];
}
else{
MailLogModel::setLog($sendMail,$subject,1);
return ["status"=>true];
}
}
My config file is here:
$config['protocol'] = "smtp";
$config['SMTPAuth'] = true;
$config['smtp_host'] = "mail.MYSERVICE.com.tr";
$config['smtp_user'] = "";
$config['smtp_pass'] = "";
$config['smtp_port'] = "25";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$config['smtp_timeout'] = 5;
How can I solve this problem?
Related
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
Iam using codeigniter
I exicuted the code on live server.
got the following error using print_debugger()
Unable to send email using PHP SMTP. Your server might not be
configured to send mail using this method.
public function sendEnquiry() {
$this->load->library('email');
$name = $this->input->post("fname");
$cemail = $this->input->post("email");
$pno = $this->input->post("phone");
$message = $this->input->post("message");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://mail.gatewaykhobar.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = '***********';
$config['smtp_pass'] = '***********';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = FALSE;
$this->email->initialize($config);
$this->email->from('info#gatewaykhobar.com','Gateway Restaurent Contact');
$this->email->to($cemail);
$this->email->subject('Gateway Restaurent Contact Enquiry');
$this->email->message($message);
$send = $this->email->send();
if($send) {
echo json_encode("send");
} else {
$error = $this->email->print_debugger(array('headers'));
echo json_encode($error);
}
}
Change smtp_port from 465 to 587.
Make sure $config['newline'] = "\r\n"; is in double quotes not single quotes.
$mail_config['smtp_host'] = 'smtp.gmail.com';
$mail_config['smtp_port'] = '587';
$mail_config['smtp_user'] = 'user#example.com';
$mail_config['_smtp_auth'] = TRUE;
$mail_config['smtp_pass'] = 'password';
$mail_config['smtp_crypto'] = 'tls';
$mail_config['protocol'] = 'smtp';
$mail_config['mailtype'] = 'html';
$mail_config['send_multipart'] = FALSE;
$mail_config['charset'] = 'utf-8';
$mail_config['wordwrap'] = TRUE;
$this->email->initialize($mail_config);
$this->email->set_newline("\r\n");
I just added the last line
A common cause of this is the way that CodeIgniter interacts with the SMTP server with regards to line breaks. Your SMTP server might require \r\n and CodeIgniter is using \n.
There is an easy fix: after your $this->email->initialize(), add the following:
$this->email->set_newline("\r\n");
That should get it working for you.
Just use "mail" for the 'protocol' array item, and that's all...
$config = array();
$config['useragent'] = $system_name;
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "mail"; //use 'mail' instead of 'sendmail or smtp'
$config['smtp_host'] = "your domain name";
$config['smtp_user'] = $from;
$config['smtp_pass'] = "*************";
$config['smtp_port'] = 465;
$config['smtp_crypto'] = 'ssl';
$config['smtp_timeout'] = "";
$config['mailtype'] = "html";
$config['charset'] = "utf-8";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$config['validate'] = FALSE;
It looks like the mail server is hosted by yourself as well, try sending email from any e-mail client. If it fails - there's a problem with your mailserver config, not the code you pasted - check the server logs.
I am using much time Run my configure code in localhost but it always gives me an error (Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.)
But when run this Below code in my server it works for me.
application>controller>Sendingemail_Controller.php
public function send_mail() {
$this->load->library('email');
$config = array();
$config['protocol'] = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
$config['smtp_host'] = "ssl://smtp.googlemail.com";// you can use 'smtp.googlemail.com' or 'smtp.gmail.com' instead of 'ssl://smtp.googlemail.com'
$config['smtp_user'] = "my#gmail.com"; // client email gmail id
$config['smtp_pass'] = "******"; // client password
$config['smtp_port'] = 465;
$config['smtp_crypto'] = 'ssl';
$config['smtp_timeout'] = "";
$config['mailtype'] = "html";
$config['charset'] = "iso-8859-1";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$config['validate'] = FALSE;
$this->load->library('email', $config); // intializing email library, whitch is defiend in system
$this->email->set_newline("\r\n"); // comuplsory line attechment because codeIgniter interacts with the SMTP server with regards to line break
$from_email = $this->input->post('f_email'); // sender email, coming from my view page
$to_email = $this->input->post('email'); // reciever email, coming from my view page
//Load email library
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject('Send Email Codeigniter');
$this->email->message('The email send using codeigniter library'); // we can use html tag also beacause use $config['mailtype'] = 'HTML'
//Send mail
if($this->email->send()){
$this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
echo "email_sent";
}
else{
echo "email_not_sent";
echo $this->email->print_debugger(); // If any error come, its run
}
}
and my view page where I defined f_email and email comes through post method.
application>view>emailtesting.php
<html>
<head>
<title> Send Email Codeigniter </title>
</head>
<body>
<?php
echo $this->session->flashdata('email_sent');
echo form_open('/Sendingemail_Controller/send_mail');
?>
<input type = "email" name = "f_email" placeholder="sender email id (from)" required />
<input type = "email" name = "email" placeholder="reciever email id (to)" required />
<input type = "submit" value = "SEND MAIL">
<?php
echo form_close();
?>
</body>
if some error comes again please visit official documentation below:
https://codeigniter.com/user_guide/libraries/email.html
For anyone else who finds this error, has set the settings mentioned elsewhere (even Codeigniter 4) but still getting tht error, one way to test what is going on is from the server console and using telnet. For example:
telnet smtp.yourprovider.com 587
Then test against a different provider and see if that works. If your provider doesn't but another does then the problem is with your provider and you should contact them. If both can't connect then you should speak with your webhost.
I've found another solution. I had the same problem: (Codeigniter 4 and the issue with php smtp), and the reason was 2-step verification of my gmail account, from which I wanted to send emails in my app. I fixed it by getting from my gmail account, password for my app. It works, at last.
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'] = '';
}
email is getting send at local but giving error when site uploaded
here is code of library please help
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Emaillib {
function send_email($fromEmail, $fromName, $details) {
$CI = & get_instance();
$CI->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'abc#gmail.com'; // Email
$config['smtp_pass'] = '*****'; // Password
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$CI->email->initialize($config);
$CI->email->from($fromEmail, $fromName);
$CI->email->to('abc#xyz.com'); // To Email
$CI->email->reply_to($fromEmail, $fromName);
$CI->email->subject('Enquiry through Website');
$CI->email->message($details);
$isSent = $CI->email->send();
//echo $CI->email->print_debugger();
if (!$isSent) {
return 'false';
}
return 'success';
}
}
?>
Because you said that it works fine locally it indicates that it is a problem with the code but rather with the server configuration. It's hard to say what the exact issue is but I would do the following
Check the server log files for any errors
Make sure the you have enabled SSL in your php.ini by check that the following line is - uncommented extension=php_openssl.dll
Make sure that port 465 is open
Try those to start with and see what happens
i have a problem in sending email in codeigniter.
$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'] = "html";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
and here is my code when sending the email
public function send_email_accountability($C11,$C12)
{
date_default_timezone_set('Asia/Manila');
$this->load->library('email');
$this->email->set_mailtype("html");
$this->email->from('noreply#smsgt.com', 'company email');
$this->email->to($C11);
$this->email->subject('Accountability for'. " ". $C12);
$this->email->message("testing");
$check = $this->email->send();
//echo $this->email->print_debugger();
if ($check){
$data = "true";
}
else{
$data = "false";
}
}
when i'm sending email with plain text in MESSAGE it works fine. but the problem is when i'm sending email with HTML scripts, it will not produce error but it will not send to the user and the email will not be received using MS OUTLOOK. can someone help me with this problem? thanks guys !
It would help if you can provide the possible error being returned by echo $this->email->print_debugger();, so why not just enable it at the moment then run your current code.
Alternatively, try this:
public function send_email_accountability($C11,$C12)
{
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'] = "html";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('noreply#smsgt.com', 'company email');
$ci->email->to($C11);
$ci->email->subject('Accountability for'. " ". $C12);
$ci->email->message("testing");
$check = $ci->email->send();
//echo $ci->email->print_debugger();
if ($check)
$data = "true";
else
$data = "false";
}
EDIT
Since you mentioned on comment that the echo $ci->email->print_debugger(); returns "Your message has been successfully sent using the following protocol" it just simply means that there is no syntactically wrong in your script. Like I said, my thoughts would be mail server issue.
If I will suggest this will be how I will be debugging your issue:
I'll replace $C11 with a Gmail address in $ci->email->to($C11); then run my current script and see if the issue of delay is the same.
Replace your current SMTP server credentials with something like Mandrill as sure its reporting log will definitely give you a hint of what is happening.
But either way, I guess you'll still end up digging something on your mail server (#smsgt.com). If I were you, I will reach out to your server administrator and start looking for clues in the mail server logs.
Try adding this:
$this->email->priority(3);
You can find more information here: http://ellislab.com/codeigniter/user-guide/libraries/email.html
You haven't initialize your email library with config values that you have set.
You just need to add below line in your code.
$this->email->initialize($config);
public function send_email_accountability($C11,$C12)
{
date_default_timezone_set('Asia/Manila');
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
//$this->email->set_mailtype("html");
$this->email->from('noreply#smsgt.com', 'company email');
$this->email->to($C11);
$this->email->subject('Accountability for'. " ". $C12);
$this->email->message("testing");
$check = $this->email->send();
//echo $this->email->print_debugger();
if ($check){
$data = "true";
}
else{
$data = "false";
}
}
Use something like this
$this->load->library('email', array(
'protocol' => 'mail',
'smtp_host' => 'ssl://mail.smsgt.com',
'smtp_port' => '25',
'smtp_user' => 'myemail#smsgt.com',
'smtp_pass' => '',
'newline' => '\r\n',
'crlf' => '\r\n',
'mailtype' => 'html'
));
$this->email->to($C11);
$this->email->from('noreply#smsgt.com', 'company email');
$this->email->subject('Accountability for'. " ". $C12);
$this->email->message("testing");
if( $this->email->send() ) {
return TRUE;
} else {
return FALSE;
}
try this code here's my code i use in sending email
function emailformat(){
$config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol.
$config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address.
$config['smtp_user'] = 'test#yahoo.com.ph'; // SMTP Username.
$config['smtp_pass'] = '#password'; // SMTP Password.
$config['smtp_port'] = '25'; // SMTP Port.
$config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds).
$config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap.
$config['wrapchars'] = 76; // Character count to wrap at.
$config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
$config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.).
$config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address.
$config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal.
$config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
$config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
$config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode.
$config['bcc_batch_size'] = 200; // Number of emails in each BCC batch.
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('test#yahoo.com.ph', 'Robot');
$this->email->to('test#yahoo.com.ph');
$this->email->subject('Expiration Notification');
$this->email->message('<html><body>This Message is to notify!</body></html>');
$this->email->send();
}