Welcome Guest, Not a member yet? Register   Sign In
Same form to different e-mail addresses and not the same content
#1

[eluser]Elias Rufino[/eluser]
Hello guys.

I have some forms, and when the user send it, some get an e-mail. This works fine.

I need to send a confirmation to the user that the form was filled and it was ok. And I need to send another e-mail to another person, with nearly the same data, but with things a little different.

So, how can I send two e-mails, to two different people and with different content, using the data from a single form?

Thanks in advance,


Elias
#2

[eluser]Elias Rufino[/eluser]
If I use
Code:
$this->email->clear();
will I lost the form data?
#3

[eluser]CroNiX[/eluser]
No, it only clears the data in the email class, but I'm not sure if you need it. It will reset the entire email object.

Have you tried sending the first email and then just overriding these fields and send a second time with the new formatting?
email::to()
email:Confusedubject()
email::message()

post your code...
#4

[eluser]Elias Rufino[/eluser]
I will try some things and post it asap.

Thank you for your attention,


Elias
#5

[eluser]Elias Rufino[/eluser]
Hello again guys. It's solved.

I will not post the form code, but if someone needs it, just tell me.

I have some validation to this form, the controller do that. So, I have things like that:

Code:
public function index()
{
        $output[] = NULL;
        // (...) - There are some things here, like captcha...
if ($this->form_validation->run() === FALSE)
{
            $output['content'] = $this->load->view('contact', $data, TRUE);
}
        else
        {
            $mail['ip'] = $this->input->server("REMOTE_ADDR");
            $mail['date'] = date('d/m/Y H:i:s');
            $mail['subject'] = $this->input->post('subject', TRUE);
            $mail['name'] = $this->input->post('name');
            $mail['email'] = $this->input->post('email');
            $mail['phone'] = $this->input->post('phone');
            $mail['msg'] = $this->input->post('msg', TRUE);

            $this->load->library('email');

            $this->email->from('some@email', 'Name from sender');
            $this->email->to('who_receive@email');

            $this->email->subject($mail['subject']);
            $this->email->message("IP: ".$mail['ip'].
                                  "\nDate: ".$mail['date'].
                                  "\nName: ".$mail['name'].
                                  "\nE-Mail: ".$mail['email'].
                                  "\nPhone: ".$mail['phone'].
                                  "\nSubject: ".$mail['subject'].
                                  "\n\nMessage: \n".$mail['msg']);

            $this->email->send(); // Here the first e-mail is sent

            $msg1 = 'Hello ';
            $msg2 = '. Great to receive your contact. We will call you as soon as possible.';

            $this->email->from('who_sends@email', 'Your Contact');
            $this->email->to($mail['email']); // will send the new mail to the address person filled in the form

            $this->email->subject($mail['subject']); // or can use another subject, just to test
            $this->email->message("Data: ".$mail['data'].
                                  "\n".$msg1.
                                  "".$mail['name'].
                                  "".$msg2.
                                  "\n".
                                  "\nNice to talk to you - www.yoursite.com");

            $this->email->send();

            $this->session->set_flashdata('success', 'Success. Your contact was sent.');

            redirect(site_url('contact'), 'location');
        }

  $this->load->view('layouts/default', $output);
}

So, CroNiX give me the tip and it really works. I can just run and send it in a normal way, after the first e-mail is sent.

It's just a test, the message to the second e-mail should be better organized.


Thank you very much.


Hugs,



Elias




Theme © iAndrew 2016 - Forum software by © MyBB