error during sending email with codeigniter? - codeigniter

Email is not sent by codeigniter.please check and identify the erros.
MY controller code is:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'bilalshabbir3210#gmail.com', // change it to yours
'smtp_pass' => 'my pasword', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '<h4>Email comessss</h4>';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('bilalshabbir3210#gmail.com'); // change it to yours
$this->email->to('bilalshabbir0909#gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
And error comes:
[]
enter image description here

The error makes it appear that your code cannot contact the SMTP server you've told it to use. A quick google implies that the server should be smtp.gmail.com.

Please use the following settings, this work very well with google
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_crypto' => 'ssl',
'smtp_timeout' => '30',
'smtp_user' => 'your_mail#gmail.com', // change it to yours
'smtp_pass' => 'your_gmail_password', // change it to yours
'charset' => 'iso-8859-1',
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => 'html',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('your_mail#gmail.com'); // change it to yours
$list = array('destination_list#gmail.com'); // change it to yours
$this->email->to($list);
$this->email->subject('This is an email test');
$message = '<h4>Email comessss</h4>';
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
} else {
show_error($this->email->print_debugger());
}

Related

How to remove html special characters when sending email using Codeigniter?

I am using Codeigniter email function to send emails. But the email which I am receiving is in improper format as the mail body contains the html tags. How to remove these tags ?
Code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxxxxxxxx',
'smtp_pass' => 'xxxxxxxxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'newline'=>"\r\n",
);
// Upload file
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($sendermail, $sendername);
$this->email->to($receivermail);
$this->email->subject($subject);
$this->email->message($message);
The email which I am getting is like below:
"<p><em><strong>TEST BODY 3</strong></em></p>"
How to get rid of the above html tags?

How to send a mail using gmail smtp in codeigniter

I want to send an email from my Gmail account through the website. how do I do that? I've tried every possible way but couldn't get the desired output.
public function mailuser(){
$config = Array(protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com','smtp_port' => 465,'smtp_user' => 'xxxx#gmail.com','smtp_pass' => 'xxxx','mailtype' => 'html');
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
if($this->email->send()){
echo 'Success email Sent';
echo $this->email->print_debugger();
}
else{
echo 'Email Failed To Send';
echo $this->email->print_debugger();
}
}
I think you are using wrong parameters in config like ssmtp
protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com'
Your config array should look like :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
$result = $this->email->send();
Also verify to enable extension extension=php_openssl.dll in php.ini.
if not please remove ;

fsockopen(): unable to connect to smtp.gmail.com:465 codeigniter live server

This code gives me an error when it is in live server. Its running in localhost but not running in live server. It gives error fsockopen():unable to connect
public function forgetPassword()
{
if(isset($_POST['email']) && !empty($_POST['email']))
{
$result = $this->Db_Function->loadDataForUpdate('wc_usr','wc_email',$_POST['email'],'nor');
if($result)
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'nileshivarni#gmail.com',
'smtp_pass' => 'Nilesh#1234',
'smtp_port' => 465,
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
$this->email->initialize($config);
$this->email->from('nileshivarni#gmail.com','Varni IT Solution');
$this->email->to($_POST['email']);
$this->email->subject('Password Recovery');
$msg = '<html><head></head><body>';
$msg .= '<p>Dear ' . $result[0]['wc_fullname']. ',</p>';
$msg .= '<p> <strong >Here is your Email and Password</strong></p>';
$msg .='<p>Email : <strong>'.$result[0]['wc_email'].'</strong></p>';
$msg .='<p>Password : <strong>'.base64_decode($result[0]['wc_password']).'</strong></p>';
$msg .='<p>Thank you</p>';
$msg .='<p>The team at Varni IT Solution</p>';
$msg .='</body></html>' ;
$this->email->message($msg);
if($this->email->send()){
$response['error'] = '1';
$response['success'] = "Your Password is successfully send to your email address !";
echo json_encode($response);
}
}
else
{
$response['error']='2';
$response['errorMsg']='Sorry ! Your Email is not registered with us!';
echo json_encode($response);
}
}
first of all if you are in any live server then it's not necessary to define :
$config = array( 'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'nileshivarni#gmail.com',
'smtp_pass' => 'Nilesh#1234',
'smtp_port' => 465);
above values for sending a mail : just define
$config = array(
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n");
That's completed. It's work in live server.

sending mail using codeigniter

This is my send email function
public function send_requs_mail()
{
$this->load->library('email');
$config=array(
'protocol' => 'smtp',
'smtp_host' =>'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxxx#gmail.com',
'smtp_pass' => 'yyyyyy'
);
$this->email->set_newline("\r\n");
$this->email->initialize($config);
$this->email->from($this->input->post('from'), 'iftekhar');
$this->email->to($this->input->post('to'));
$this->email->subject('Email Test');
$this->email->message($this->input->post('message'));
if($this->email->send())
{
echo'your email was sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Now when I press Send button I get successful message I mean I get message "your email was sent" but in email Inbox I didn't get any message.
check if $this->input->post('from') and $this->input->post('to') return valid email addresses, otherwise it will not send the email!
use this $config Array
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_crypto' => 'ssl',
'smtp_user' => 'your mail',
'smtp_pass' => 'your password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
And to install SSL
First see if there is open-ssl extension in your php.ini file if not then put the below code in the ini file in extension part.
extension=php_openssl.dll
Restart the Apache service.

Contact from in codeigniter without using gmail user and password

I used the following code in controller of my contact form.
public function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email#mydomain.com',
'smtp_pass' => 'myPassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
Can i send the email without using "smtp_user" and "smtp_pass"?
Just use mailprotocol in the config.
See the docs: http://ellislab.com/codeigniter/user-guide/libraries/email.html
You can use the default config and send email like:
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();

Resources