Email codeigniter SMTP error was encountered: 450 4.7.1

Asked

Viewed 1,117 times

0

does that you can explain to me how I send email from a form by the servers Ocaweb, I have a website of a client hosted in Ocaweb, but the sending form does not work using the e-their mail, I wonder if anyone has ever had a similar problem on Ocaweb 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 sends normal with other smtp servers, the settings are in config/email.php and work, except in Locaweb, how do someone 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

  • Error appears?

  • 1

    yes 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.

2 answers

2

I was able to solve the problem, actually Locaweb has an anti-span system, when you send an email with html template, you can’t leave the field of who sends the email registered by the sender, in fact, the form should be sent by an e-mail 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 within 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();

0

I guess I missed starting 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);
  • Hello, the lib is already being loaded in the autoload of codeigniter, and the settings are being loaded by email.php in the config of codeigniter, so the localhost is working normal, but the server of Locaweb is not.

  • Then do the test, take the autoload and leave only in the email controller... Because I work like this with Ocaweb and it doesn’t give problems...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.