codeigniter bcc doesn't work - codeigniter

Codeigniter "bcc" doesn't work, But the same code with "to" works just fine! Any suggestions why this happens and how to fix it?
Here's my code:
$email = "myEmail#myWebsite.com";
$subject = "my subject";
$message = "my message";
$this->email->set_mailtype("html"); // In my actual code this is needed
$this->email->from('myWebsiteEmail#myWebsite.com', 'Info');
// $this->email->to($email); // It works with this code
$this->email->bcc($email); // It doesn't work with this code
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
Any suggestions would be appreciated!

You have to have a to to be able to bcc
Try adding an email to the to as well as a bcc and it should work.

You may need to enable bcc_batch_mode in email config.
By default is value is FALSE.

It doesn't need a $this->email->to() all you need to do is set $config['bcc_batch_mode'] = TRUE; and then add the emails like $CI->email->bcc( $bccEmailArray );. The bcc method does not work like the cc method.

Related

Sending html content as mail body laravel mail sending application

My controller is
public function basic_email() {
$data = array('name'=>"Virat Gandhi",'roll'=>"123");
Mail::send(['text'=>'mail'], $data, function($message) {
$message->to('xyz#gmail.com', 'Basil Baby')->subject
('Laravel Basic Testing Mail');
$message->from('abc#yahoo.com','Virat Gandhi');
});
echo "Basic Email Sent. Check your inbox.";
}
My blade is
Hi, {{ $name }}
your roll number is {{$roll}}
please click on the link to verify your account
Mail is being received. but the mail body is displaying html content as such. How to make verify you account a html link in mail body
Change your key text to html in your send function.
text key send data as a plain text
Mail::send( ['html' => 'mail']...
Also change {{}} to {!! !!}
Reference:
Laravel -> Mail
If you are trying to verify registered users, I would suggest you to use Laravel's build-in verification system.
You can follow the link:
Laravel email verification

Email never received If there is a URL inside message body - Codeigniter

I try to send an email with codeigniter library. Simple plain email working perfect but as soon as I put any URL like www.abc.com, codeigniter gives message that email sent but I never received. I change the mailtype to HTML with no luck.
Any ideas please.
$this->load->library('email');
$config['mailtype'] = "html";
$config['charset'] = "utf-8";
$config['priority'] = "1";
$this->email->initialize($config);
$this->email->from("myemail#gmail.com", 'TS');
$this->email->to("myemail#gmail.com");
$this->email->subject('Test Email');
$txt_site_name = "www.google.com";
$this->email->message("This is test email with link --> ".$txt_site_name);
if($this->email->send())
{
echo "The email has been sent";
}else{
echo "Could not send the email";
show_error($this->email->print_debugger());
}

Zend email debug

I am trying to find an equivalent way to debug an email in Zend like I can in cakePHP. I want to see my test output before I send an email out for testing. I could just send the email to myself, and work bugs out that way, but I find that tedious.
//zend mail
$mail = new Zend_Mail();
$mail->setBodyHTML($content);
$mail->setBodyText($content);
$mail->setFrom('noreply#joe.com', 'Security Notification');
$mail->addTo('joeschmo#joe.com');
$mail->setSubject('(Security Notify) New Security Request');
//$mail->send();
//Equivalent to this from cakePHP
$this->Email->delivery = 'debug';
$this->Email->send('test message');
debug($this->Session->read('Message.email'));
die();
something like:
die($mail->getBodyHtml());
or
die(print_r($mail));
For your content in HTML, you can simply write:
echo $content; exit();
And for your content in plain text write:
echo '<pre>' . $content . '</pre>'; exit();

codeigniter : using flash data but no new page load?

Usually, I just set a $feedback var or array and then check for that to display in my views.
However, it occurred to me I should perhaps use flashdata instead.
The problem is sometimes - for say an edit record form, I may simply want to reload the form and display feedback - not redirect. when i use flashdata, it shows but then it shows on the next request as well.
What would be the best practice to use here?
CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared.
u use hidden field for that
I would use the validation errors from the Form validation class and load those directly to the view in its 2nd argument.
$this->form_validation->set_error_delimiters('<p>', '</p>');
$content_data = array();
if (!$this->form_validation->run()) {
$content_data['errors'] = validation_errors();
}
$this->load->view('output_page', $content_data);
Then check in your view whether $errors isset.
Controller:
$data['message'] = 'some message you want to see on the form';
$this->load->view('yourView', $data);
View:
if (isset ($message)) : echo $message; endif;
...

not able get post form submit values in codeigniter

I tried a simple form submit But I am not able to get the form values on controller using $this->input->post as well as $_POST[] methods. My view part is
<html>
<head>
<title> Feedback page</title>
</head>
<body>
<?php echo form_open('feedback/save'); ?>
<p>
<label>name: </label>
<?php echo form_input('name'); ?>
</p>
<p>
<label>Email: </label>
<?php echo form_input('email'); ?>
</p>
<p>
<label>Feedback: </label>
<?php echo form_textarea('feedback'); ?>
</p>
<p>
<?php echo form_submit('submit','Submit'); ?>
</p>
<?php echo form_close(); ?>
</body>
</html>
and controller part is
<?php
class Feedback extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model("MFeedback");
}
function index() {
$this->load->view('home/feedback_view.php');
//print "loaded";
}
function save() {
print "called";
print_r($this->input);
$name = $this->input->post('uname');
$email = $this->input->post('email');
$feedback = $this->input->post('feedback');
print $name . $email . $feedback;
$this->index();
}
}
?>
I am not sure what went wrong here or is there any config settings I need to look in to it.?
I have found out the problem. It is actually with the rewrite rule. Make sure you have rewrite rule like
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
on root folder of codeigniter.
Take a look at this:
http://codeigniter.com/user_guide/libraries/form_validation.html#validationrules
I had a similar issue when I started off using CI. You need to set at least one validation rule for the form and then check to see if the form submitted met that rule. You can then access the submitted form data like you are doing above..
It's been a while since I've used CI but something like this should solve your problem:
(Taken from the link above)
$this->load->library('form_validation');
$this->form_validation->set_rules('uname', 'Username', 'required');
$this->form_validation->set_rules('email', 'Password', 'required');
$this->form_validation->set_rules('feedback', 'Feedback', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE)
{
// Here is where you do stuff when the submitted form is invalid.
$this->load->view('myform');
}
else
{
// Here is where you do stuff when the submitted form is valid.
print "called";
print_r($this->input);
$name = $this->input->post('uname');
$email = $this->input->post('email');
$feedback = $this->input->post('feedback');
print $name . $email . $feedback;
$this->index();
}
Hope that helps you in someway.. :)
your url address should be same as config->config.php->$config['base_url']
if your url address like
http://www.test.com
then your configh should be
$config['base_url'] = 'http://www.test.com/';
I was facing the same problem as you since the past half hour couldn't get anything to work. I tried your solution, it didn't help. But you were right it has to do with routing.
I was also passing other variables to my action like :
domain/controller/action/value1/value2
when I had my form submit data to :
domain/index.php/controller/action/value1/value2
it solved the problem. I am guessing if you pass values at the end the post variables don't work as expected. I know its supposed to work and I guess it does as well. Think its a problem with setting .htaccess correctly.
Thanks for the ideas that I solved my probs. I've got the same issue. My code worked well in WAMP, but when I moved to LAMP, I got all sorts of wired problems that I've never met before, and not getting any form post value was one of them.
According to the suggestion above:
I used form_open(index.php/controller/method) instead of form_open(controller/method) and it worked straight away.
However I got my index.php removed, and it's not shown in the address bar neither. As I said it's wired...
Use form action='domain/index.php?/controller/function name/parameter1/parameter2'
For example your domain is abc.com, controller is get, function name value,and parameter to be passed in functions are a and b
then just write the form action like following way.
<form action='http:/abc.com/index.php?/get/value/a/b' method='post' >
I solved my problem this way. Hope it will work for you.
Thanks
Firstly, In your view you've specified the name of your one input to be name, in your controller you're looking in post for uname.
Secondly, I don't remember if CodeIgniter does the same to $_POST but it definately destroys the $_GET array. If you want an associative array of all post inputs you can call this:
$this->input->post();
Thirdly, In a very very rare case your inputs might be getting blocked by XSS Filtering, you can stop this from happening by calling it like this (only for inspection purposes to see what's wrong, dont use this in production):
$this->input->post(NULL, FALSE);
If something is generally wrong, these calls will return FALSE, you should test for this using the === operator, as it will only match FALSE where == will match NULL as well.
Fourthly, You should test quickly using a simple html form, it looks like you're building your form right with the form helper but it never hurts to use a straightforward HTML Form for quick testing.
Other than that, you'll need to provide more information about your environment / configuration / generated html / etc... for us to figure out. You really didn't give us a lot to work with.
Well I have faced the same issue and following additions to .htaccess helped solved my problem.
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
$data = array('id' => 'email',
'name' => 'email',
'class' => 'form-control');
echo form_input($data);
Just a quick mention that if you use an array to set up your inputs etc.. dont forget to include the name => 'your_desired_post_variable_name' in your array as this was my mistake, I was giving it just an id and wondering why my POST array was blank! Dont do the same! ;)
I've had a similar issue on my local ubuntu.
htaccess was properly configured but nothing inside post.
My issue was that apache didn't have mod rewrite enabled and I've fixed it by running these commands:
sudo a2enmod rewrite
sudo service apache2 restart
After that, all my post data went trough.
Hope that helps the next person who has the same issue

Resources