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
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";
}
I can't send email from my codeigniter. it always reload when i press send button. I don't know what wrong with this code. please help me, so i can send the attached email to destination How can i solve this. The code is below :
function send_quotation($no, $email_to, $id_ticket, $problem, $action, $nama)
{
$this->load->model('service_tracking/trans_service_model');
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'examplefrom#gmail.com';
$config['smtp_pass'] = 'password123';
$config['priority'] = 1;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['starttls'] = TRUE;
$data = $this->trans_service_model->get_emaildata($id_ticket);
$this->email->initialize($config);
$this->load->library('email', $config);
$this->email->set_newline('\r\n');
$this->email->from('examplefrom#gmail.com', 'Example corporation');
$this->email->to('exampleto#gmail.com');
$data = $this->trans_service_model->get_emaildata($id_ticket);
$this->email->initialize($config);
$this->load->library('email', $config);
$this->email->set_newline('\r\n');
$this->email->from('examplefrom#gmail.com', 'Example Corporation');
$this->email->to('exampleto#gmail.com');
$this->email->subject('['.$no.'] - '.$nama.' - Quotation Repair');
$message = "
This is the email contain quotation";
$this->email->message($message);
$this->email->attach('./quotation/'.$no.'.pdf');
$this->email->send();
echo $this->email->print_debugger();
}
do like this
if (!$this->email->send()) {
echo $this->email->print_debugger();
} else {
echo "Success";
//redirect();
}
$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();
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();
}