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

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

Related

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";
}

Can't send email from codeigniter. Just reloading page

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();
}

SMTP Host Issue in China

I have an issue regarding smtp using codeigniter email library. It works fine with smtp.gmail.com but I have to use vpn in this case. I found other solutions like smtp.exmail.qq.com, smtp.mail.yahoo.com or smtp.sina.com but when you send the form typing your email in email field its being sent only with the email you provided in smtp user. Further please look at my code and screen shotenter image description here:
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email =
'info#sample.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.exmail.qq.com';
//'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'myemail#exmail.qq.com';
$config['smtp_pass'] = 'my password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);

Gsuite account won't send emails codeigniter

I just set up google mx records for my domain. When i use my normal gmail account, emails are sent but when I use my gsuite account, the mails are not sent. I am hosting my site on siteground. However I can receive emails from other email accounts on my gsuite account.
$this->load->library('email');
$subject = 'Subject';
$message = 'My message';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465
$config['smtp_user'] = 'info#mydomain.com';
$config['smtp_pass'] = 'my_password';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$config['validation'] = TRUE;
$this->email->initialize($config);
//send mail
$this->email->from('info#mydomain.com', 'MyDomainName');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
//echo json_encode($this->email->print_debugger());
if($this->email->send())
return true;
else
return false;
You didn't attach any error message, but since it's working for your other Gmail accounts, try checking if turning on access to "less secure apps" for this account solves this issue and report back.
https://myaccount.google.com/lesssecureapps
(Don't forget to choose the right account, if you're logged in to several ones).
I had similar problem, I had to create a App Password to work (details here: https://support.google.com/accounts/answer/185833?hl=en)
Once the App Password was created I used:
$subject = 'Your subject';
$message = 'Your body';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'your#email.com';
$config['smtp_pass'] = 'your app password';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$config['validation'] = TRUE;
$this->email->initialize($config);
//send mail
$this->email->from('from#email', 'Title');
$this->email->to('to#email.com');
$this->email->subject($subject);
$this->email->message($message);

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

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;

Categories