Hey guys. I have the following scenario ...
I wanted to send an email to the user of my site. For example: - Welcome to the company So, wait until soon we will contact.
This is just an example, but in my real form I have other fields (type: name, email, address, city, state, chosen plan and others).
So, the goal would be that when he filled out the form completely, it would be sent to the email he provided at the time of registration, the message that I said more above. (Welcome .....)
obs:
- controller Contact: I have two functions, sendEmail (); and checkEmail ()
-
The error is in checkEmail () on this line $ address = $ this-> SendEmail ($ email);
The error says that the $ email variable has not been defined.
If someone has another idea to perform the same process, all help is welcome!
<?php
defined ('BASEPATH') OR exit ('No direct script access allowed');
class Contact extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('email');
$this->load->library('session');
$this->load->helper('url');
$this->load->library('form_validation');
}
public function index(){
$this->load->view('contato');
}
// funcao: envia o email informando para o usuario que o registro foi recebido
public function checkEmail(){
// config do servidor de email
$config = array();
$config ['charset'] = 'utf8';
$config ['mailtype'] = 'html';
$config ['protocol'] = 'smtp';
$config ['smtp_host'] = '';
$config ['smtp_user'] = '[email protected]';
$config ['smtp_pass'] = '';
$config ['smtp_port'] = 25;
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$address = $this->enviaEmail($email);
// formatacao do corpo de email
$this->email->from('[email protected]');
$this->email->to($address);
$this->email->subject('Confirmação de recebimento!');
$this->email->message('
<html>
<head>
<style>
.card {
border: 1px solid #ededed;
background-color: #fff;
padding: 43px 40px;
border-bottom: 1px solid #FFA100;
}
.page-footer{padding: 43px 40px;}
body{background-color:#D9EBFF;}
h2 {color: #002040; font-size: 16px;}
</style>
</head>
<body>
<div class="">
<div class="card">
<h2>Olá, seja Bem Vindo! Nome Empresa agradecece pela sua escolha!</h2><br>
<p>O seu email foi recebido pelo nosso atendimento, aguarde que entraremos em contato para mais informações</p>
</div>
</div>
<div class="page-footer">
<p>Sua Empresa | Todos os direitos reservados</p>
</div>
</body>
</html>
');
if ($this->email->send()){
echo "email enviado";
}
else{
echo "erro ao enviar";
}
}
//funcao que envia o email pro usuario que fez o registro no formulario
public function enviaEmail(){
//validacao do formulario
$this->form_validation->set_rules('nome','nome', 'required|min_length[5]|max_length[30]');
$this->form_validation->set_rules('email','email', 'required');
$this->form_validation->set_rules('mensagem','mensagem', 'required|min_length[5]|max_length[144]');
$this->form_validation->set_rules('item','item', 'required');
$data = $this->input->post();
// config servidor de email
$config = array();
$config ['charset'] = 'utf8';
$config['mailtype'] = 'html';
$config ['protocol'] = 'smtp';
$config ['smtp_host'] = '';
$config ['smtp_user'] = '[email protected]';
$config ['smtp_pass'] = '';
$config ['smtp_port'] = 25;
// recebe os valores dos campos preenchidos pelo usuario
$nome = $this->input->post('nome', TRUE);
$email = $this->input->post('email', TRUE);
$emailTo = $this->input->post('email', TRUE);
$item = $this->input->post('item', TRUE);
$mensagem = $this->input->post('mensagem', TRUE);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
// formatacao do corpo de email
$this->email->from($data['email']);
$this->email->to('[email protected]');
$this->email->subject('Entre em Contato');
$this->email->message('
<html>
<head>
<style>
.card {
border: 1px solid #ededed;
background-color: #fff;
padding: 43px 40px;
border-bottom: 1px solid #FFA100;
}
.page-footer{padding: 43px 40px;}
body{background-color:#D9EBFF;}
h2 {color: #002040; font-size: 16px;}
</style>
</head>
<body>
<div class="">
<div class="card">
<h2>Nome:</h2>'.$nome.' <br>
<h2>Email:</h2> '.$email.' <br>
<h2>Tipo de Item:</h2> '.$item.' <br>
<h2>Mensagem:</h2> '.$mensagem.' <br>
</div>
</div>
<div class="page-footer">
<p>Sua Empresa | Todos os direitos reservados</p>
<p>Este formulário foi enviado direto do site suaempresa.com.br </p>
</div>
</body>
</html>
');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
if ($this->email->send()){
$this->checkEmail();
}
else{
$this->load->view('errorEmail');
}
}
}