Email codeigniter SMTP error was encountered: 450 4.7.1

0

Can you explain how I send email from a form by the locaweb servers, I have a site from a client hosted on locaweb, however the submission form does not work using their email, I wonder if someone already had a similar problem in locaweb using codeigniter and how you solved it.

 if ( ! defined('BASEPATH')) exit('No direct script access allowed');


 $config['protocol']='smtp';
 $config['smtp_host']='smtp.xxx.xxx';
 $config['smtp_port']='587';
 $config['smtp_timeout']='60';
 $config['smtp_user']='xxxxx';
 $config['smtp_pass']='xxxxx';
 $config['charset']='utf-8';
 $config['newline']="\r\n";
 $config['mailtype']="html";
 $config['smtp_crypto'] = 'tls';



    $nome= $this->input->post('nome', TRUE);        
    $empresa = $this->input->post('nome-empresa', TRUE);    
    $telefone = $this->input->post('telefone', TRUE);      
    $celular = $this->input->post('celular', TRUE);
    $email = $this->input->post('email', TRUE);
    $cidade = $this->input->post('cidade', TRUE);
    $bairro = $this->input->post('bairro', TRUE);
    $endereco = $this->input->post('endereco', TRUE);

            $data['email'] = [
                'nome' =>$nome,
                'empresa' =>$empresa,
                'telefone' =>$telefone,
                'celular'  =>$celular,
                'cidade' => $cidade,
                'bairro' => $bairro,
                'endereco' => $endereco,
                'email' => $email    

            ];

            $mensagem = $this->load->view('template_email/index', $data, true);
            $this->email->from($email);  
            $this->email->to('email'); 
            $this->email->subject('Solicitação de Visita');        
            $this->email->message($mensagem);                   
            $this->email->send();     
            echo $this->email->print_debugger();

In localhost send normal with other smtp servers, the settings are in config / email.php and they work, except in locaweb, how do anyone know?

The error returned is this:

  

The following SMTP error was encountered: 450 4.7.1: Recipient address rejected: Access Denied Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

    
asked by anonymous 09.03.2016 / 19:54

2 answers

2

I managed to solve the problem, in reality, locaweb has an anti-span system, when you send an email with html template, you can not leave the field of those who send with the email registered by the sender, the form should be sent by an email from your domain, follow the code with the solution below, take into account that I am using codeigniter, the email library is being loaded by autoload, and the email configuration files are in an email.php file inside the config, which ensures that the configuration is already loaded,

  //configuração

  $config['protocol']='smtp';
  $config['smtp_host']='smtp.seudominio.com.br';
  $config['smtp_port']='587';
  $config['smtp_timeout']='60';
  $config['smtp_user']='[email protected]';
  $config['smtp_pass']='xxxxx';
  $config['charset']='utf-8';
  $config['newline']="\r\n";
  $config['mailtype']="html";
  $config['smtp_crypto'] = 'tls';


//controller
$nome= $this->input->post('nome', TRUE);        
$empresa = $this->input->post('nome-empresa', TRUE);    
$telefone = $this->input->post('telefone', TRUE);      
$celular = $this->input->post('celular', TRUE);
$email = $this->input->post('email', TRUE);
$cidade = $this->input->post('cidade', TRUE);
$bairro = $this->input->post('bairro', TRUE);
$endereco = $this->input->post('endereco', TRUE);

        $data['email'] = [
            'nome' =>$nome,
            'empresa' =>$empresa,
            'telefone' =>$telefone,
            'celular'  =>$celular,
            'cidade' => $cidade,
            'bairro' => $bairro,
            'endereco' => $endereco,
            'email' => $email    

        ];


        $mensagem = $this->load->view('template_email/index', $data, true);
        $this->email->from('[email protected]');  
        $this->email->to('[email protected]'); 
        $this->email->reply_to($email); //email de resposta
        $this->email->subject('Solicitação de Visita');        
        $this->email->message($mensagem);                   
        $this->email->send();     
        echo $this->email->print_debugger();
    
10.03.2016 / 16:31
0

I believe you have failed to start the lib with the settings.

$config['protocol']='smtp';
 $config['smtp_host']='smtp.xxx.xxx';
 $config['smtp_port']='587';
 $config['smtp_timeout']='60';
 $config['smtp_user']='xxxxx';
 $config['smtp_pass']='xxxxx';
 $config['charset']='utf-8';
 $config['newline']="\r\n";
 $config['mailtype']="html";
 $config['smtp_crypto'] = 'tls';
 $this->load->library('email', $config);
    
09.03.2016 / 20:33