I m trying to send an automated email from my hosting server using codeigniter smtp, but here i m facing some error with AUTH LOGIN. Successfully i can able to sending mails in my localhost with gmail smtp host, and gmail account (after allowing security for third-party apps). Here i m using webmail, so i help form you guys to fix my bugs. Thanks in Advance.
ERROR :- The following SMTP error was encountered: 0 php_network_getaddresses: getaddrinfo failed: Name or service not known Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:
from: The following SMTP error was encountered: Unable to send data: RCPT TO:
to: The following SMTP error was encountered: Unable to send data: DATA
data: The following SMTP error was encountered: etc....
Here is my code:-
$config['useragent']='CodeIgniter';
$config['protocol']='smtp';
$config['smtp_host']='ssl//mail.mydomain.com';
$config['smtp_port']='587';
$config['smtp_auth']=true;
$config['smtp_timeout']='30';
$config['smtp_user']= 'admin@mydomain.com';
$config['smtp_pass']= 'mypassword';
$config['charset']='utf-8';
$config['newline']="
";
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->set_newline("
");
$this->email->from($from, $from_name);
$this->email->reply_to($from, $from_name);
i think you have to use email library of codeigniter because it will be easy to your in email library we have to no needed to set up a SMTP mail we can send mail directly and also email library will be helpful to you in case of attachment because codeigniter by default provide attachment()
method only we have to pass path in attachment method so it will be easy to you...
you can use like that --
public function supportEmail()
{
$this->load->library('email');
$this->email->from('saurav@gmail.com', 'Saurav Garg');
$this->email->to('info@demo.com');
$this->email->subject('Live Support');
$this->email->message('Please Use This Method');
$sent = $this->email->send();
}