How to remove html special characters when sending email using Codeigniter? - 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?

Related

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 ;

error during sending email with 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());
}

Email with laravel SMTP of Godaddy account fails?

I am trying to send an email in laravel with godaddy account but I always get an error
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "501", with message "501 HELO requires valid address"
Below code I used for the sending the email in controller:
$title = 'Test email';
$content = 'Test email from shingora';
Mail::send('emails.send', ['title' => $title, 'content' => $content], function ($message) {
$message->from('robin.shingora#gmail.com', 'Shingora');
$message->subject('Test email');
$message->to('robin.shingora#gmail.com');
});
And in mail.php
return [
'driver' => 'smtp',
'host' => 'smtpout.asia.secureserver.net',
'port' => 25,
'from' => ['address' => 'example#gmail.com', 'name' => 'test'],
'encryption' => 'ssl',
'username' => 'example#gmail.com',
'password' => '********',
'sendmail' => 'D:\sendmail\sendmail -bs',
'pretend' => false,
];
Set all smtp setting in your .env file
i.e
MAIL_DRIVER=smtp
MAIL_HOST=ssl://smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=example#gmail.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=null
OR
return [
'driver' => 'smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'from' => ['address' => 'example#gmail.com', 'name' => 'test'],
'encryption' => 'ssl',
'username' => 'example#gmail.com',
'password' => '********',
'sendmail' => 'D:\sendmail\sendmail -bs',
'pretend' => false,
];
Few weeks ago I had same issue and I solved the problem by realising that GoDaddy likes to have your from and reply-to e-mail should belong to your own domain.
And it may be a problem with your hostname, so I've browsed to another SO question and found this:
Configure SwiftMailer "Local Domain" setting easily, in Symfony 2

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