Send SMTP email from cpanel - php

I am using godaddy shared hosting is there and of what i read that it's not possible to send emails using SMTP from a shared hosting is there any alternative way .. i am trying to send emails using codeigniter but it's not working at all
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
if ($this->email->send())
{
$this->set_message('forgot_password_successful');
return TRUE;
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}

Check: GoDaddy POP and SMTP Server Settings
Check the library configuration email, and your hosting provider looking email accounts created, select and view a manual configuration.
Documentation Codeigniter Email
<?php
public function sendEmailSMTP(){
$this->load->library("email");
$configEmail = array(
'useragent' => "CodeIgniter",
'mailpath' => "/usr/bin/sendmail", // or "/usr/sbin/sendmail"
'protocol' => 'smtp',
'smtp_host' => 'URL',// URL check: http://www.yetesoft.com/free-email-marketing-resources/godaddy-pop-smtp-server-settings/,
'smtp_port' => 465, // Usually 465
'smtp_crypto' => 'ssl', // or tls
'smtp_user' => 'youremail#yourdomain.com',
'smtp_pass' => 'AccountPasswordEmail',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
//Load config
$this->email->initialize($configEmail);
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject(($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
$this->email->send();
// See result
echo $this->email->print_debugger();
} // End sendEmailSMTP()

Related

Sending email from office365 sometimes not working

I've setup my email sender using outlook office365 with codeigniter 3. Below code works but sometimes it doesn't and I don't know why. Sometimes it will not work the first time I push my repo but when I tried it again, it works. I've logged the error below.
Error:
Failed to authenticate password. Error: <br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br />
Code:
public function send_mail($to_email = null, $name = '')
{
$config = array(
'protocol' => 'smtp',
'smtp_crypto' => 'tls',
'smtp_host' => 'smtp.office365.com',
'smtp_port' => 587
'smtp_user' => EMAIL_SENDER,
'smtp_pass' => EMAIL_SENDER_PASSWORD,
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'newline' => "\r\n",
'crlf' => "\n",
'starttls' => true
);
$from_email = EMAIL_SENDER;
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from_email, 'Power App');
$this->email->to($to_email);
$this->email->subject('Password Reset');
$this->email->set_crlf("\r\n");
$data["user"] = $to_email;
$data["name"] = $name;
$this->email->message($this->load->view('email/email_reset_password_template', $data, true));
//Send mail
if ($this->email->send())
return "Email sent successfully.";
else {
return $this->email->print_debugger();
}
}
UPDATE:
Its now always working when I use PHPMailer. Haven't really discover why its not always sending email using email library.

Sending Mail Using Gmail In Codeigniter

I will try to send mail using gmail in codeigniter. I write code as given bellow. When i upload it on c panel it will work properly for 2 days but after that it stop working.
//Load email library
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxx',
'smtp_pass' => 'xxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype('html');
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>MY WEBSITE</h1>';
$htmlContent .= '<p>OTP For Reset Your Password.</p>';
$this->email->to($uemail);
$this->email->from('xxxxxxxx','MyWebsite');
$this->email->subject('MESSAGE');
$this->email->message($htmlContent);
//Send email
$this->email->send();
I experienced the same thing where the email was not sent and there was no error, it turned out that when I checked my Gmail account it wasn't always on the Primary tab (make sure it wasn't in the Spam folder either). Sent but in the Promotions tab.

Say Email sent but nothing is recieved when sent email using Codeigniter

I have used this several ways but can't seem to get it working. I am running it on live server.
I am using bigrock hosting and as per their document it says just use "localhost" as smtp host. Link
It says email sent but I get nothing..
public function index() {
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'localhost',
'smtp_port' => '587',
// Other way it say Email sent
//'smtp_host' => 'ssl://localhost',
//'smtp_port' => '465',
'smtp_user' => 'support#abc.com',
'smtp_pass' => 'sdfsfsdfsd'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('support#abc.com', 'ABC');
$this->email->to('abc#gmail.com');
$this->email->subject('Test');
$this->email->message('Success');
if ($this->email->send()) {
echo 'Email Sent';
} else {
show_error($this->email->print_debugger());
}
}
Thanks in advance.
This line: $this->email->to('abc#gmail'); make it 'abc#gmail.com' and make sure it is existing..If it still doesn't work, try a legit email from inside you email->from.

Email not working in Codeigniter

I am working on booking app in codeigniter. I am stuck in email sending from localhost.
I am using gmail smtp for sending email. I am using email/booking_email.php view file as email template. But, When I run website page that contains email sending script in localhost, it keeps loading but email is not sent.
$email = "atomambition#gmail.com";
$name = "Wiyo HK";
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'atomambition#gmail.com',
'smtp_pass' => '********',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $email_config);
$this->email->from($email, $name);
$this->email->to($this->bookings_class->get_email());
$this->email->reply_to($email, $name);
$subject = 'This is Booking email from Wiyo HK';
$this->email->subject($subject);
$data = array('customer_name' => 'Avash Poudel');
$message = $this->load->view('email/booking_email', $data, TRUE);
$this->email->message($message);
echo $result = $this->email->send();
Localhost does not support sending emails directly unless configured.
In the localhost it does not work like this . For testing use mail() protocol on localhost and smtp on server.
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
Add this in $email_config.
After that you need to initialise your config array.
So write this $this->email->initialize($email_config);
Also use $this->email->print_debugger() to debug

Send email by Email Class in codeigniter with Gmail

I want send a email by Email Class in codeigniter with gmail, but i get following error:
Error:
A PHP Error was encountered Severity: Warning Message:
mail() [function.mail]: Failed to connect to mailserver at
"ssl://smtp.googlemail.com" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set() Filename:
libraries/Email.php Line Number: 1553
This is my full function in controll:
function send_mail(){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'xyz#gmail.com';
$config['smtp_pass'] = 'xxxxxxx';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('neginph#gmail.com', 'Negin Phosphate Shomal');
$this->email->to('neginfos#yahoo.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
if($this->email->send())
{
echo 'Your email was sent, successfully.';
}
else
{
show_error($this->email->print_debugger());
}
}
I changed SMTP in php.ini as this:
SMTP = ssl://smtp.googlemail.com smtp_port = 25
What do i do?
With respect
this is what worked for me
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $email_config);
$this->email->from('someuser#gmail.com', 'invoice');
$this->email->to('test#test.com');
$this->email->subject('Invoice');
$this->email->message('Test');
$this->email->send();
Have you turned on php_openssl?
Try to uncomment extension=php_openssl.dll in your php.ini file.
This is working for me on localhost:
<?php
class Email extends CI_controller
{
function index()
{
$this->load->library('email');
$this->load->helper('url');
$this->load->helper('form');
$config= Array(
'protocol' =>'localhost',
'smtp_host' => 'localhost',
'smtp_port' => 'localhost',
'smtp_user'=> 'root',
'smtp_pass' =>''
);
$this->load->library('email','$config');
$this->email->set_newline("\r\n");
$this->email->from('nisha#gmail.com','nisha');
$this->email->to('cse1473#gmail.com');
$this->email->subject('this is email with subject');
$this->email->message('it s working properly');
if($this->email->send())
{
echo "your email send";
}
else
{
show_error($this->email->print_debugger());
}
}
}
?>

Categories