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();
Related
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?
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 ;
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());
}
I am using codeigniter to send email.
function forget_pw() {
$this->load->library('email');
$config['smtp_host'] = 'host address';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$this->email->initialize($config);
$this->email->from('admin#email.com', 'Admin');
$this->email->to('test#yahoo.com.hk');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
No any error show in console. But the email didn't send out.
You can create a function like this:
public function sendEmail($subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'xxxxx.xxxxxx.xxxxx',
'smtp_port' => 465,
'smtp_user' => 'xxxxx.xxxxxx.xxxxx',
'smtp_pass' => 'xxxxx.xxxxxx.xxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxxx.xxxxxx.xxxxx');
$this->email->to('xxxxx.xxxxxx.xxxxx');
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
And use it like this $this->sendEmail('Title', 'Message'); Good luck
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.