mysql_query() expects Parameter 1 to be string, Resource Give

Asked

Viewed 221 times

0

So I searched my code to find a solution, but the error may be database, every time I finish the registration was to be sent an email, but this error.

Warning: mysql_query() expects Parameter 1 to be string, Resource Given in C: xampp htdocs Controls registering.php on line 67 email sending: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php    
    $email = $_POST['email'];

    $result_leados = "INSERT INTO tb_usuarios email VALUES ('$email')";
    $resultado_leados = mysql_query($con, $result_leados);

    //Inicio Enviar e-mail
    require 'PHPMailer/PHPMailerAutoload.php';

    $Mailer = new PHPMailer();

    //Define que será usado SMTP
    $Mailer->IsSMTP();

    //Enviar e-mail em HTML
    $Mailer->isHTML(true);

    //Aceitar carasteres especiais
    $Mailer->Charset = 'UTF-8';

    //Configurações
    $Mailer->SMTPAuth = true;
    $Mailer->SMTPSecure = 'ssl';

    //nome do servidor
    $Mailer->Host = 'localhost';
    //Porta de saida de e-mail 
    $Mailer->Port = 465;

    //Dados do e-mail de saida - autenticação
    $Mailer->Username = '[email protected]';
    $Mailer->Password = 'modercontrol';

    //E-mail remetente (deve ser o mesmo de quem fez a autenticação)
    $Mailer->From = '[email protected]';

    //Nome do Remetente
    $Mailer->FromName = 'Controla estoque';

    //Assunto da mensagem
    $Mailer->Subject = 'Titulo - Confirmação de email';

    //Corpo da Mensagem
    $mensagem = "Olá <br><br>";
    $mensagem .= "Confirme seu e-mail acessar o sistema, após isso execute o login. <br> <br>";
    $mensagem .= "Sua Conta Foi Desbloquueada</a><br> <br>";
    $mensagem .= "Se você recebeu este e-mail por engano, simplesmente o exclua.<br> <br>";
    $mensagem .= "Controla estoque";

    $Mailer->Body = $mensagem;

    //Corpo da mensagem em texto
    $Mailer->AltBody = 'conteudo do E-mail em texto';

    //Destinatario 
    $Mailer->AddAddress($email);

    if($Mailer->Send()){
        echo "E-mail enviado com sucesso";
    }else{
        echo "Erro no envio do e-mail: " . $Mailer->ErrorInfo;
    }

    //Fim Enviar e-mail
?>
  • Attention: concatenating query as string runs the risk of SQL Injection attack. https://www.tecmundo.com.br/tecmundo-explica/113195-sql-injection-saiba-tudo-ataque-simples-devastador.htm

  • The first error is that the query should be the first parameter.

  • I put the query as the first parameter, but the SMTP connect() error continues

  • E-mail error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

1 answer

1

The SQL command is wrong, the name of the fields in the insert should come in parentheses, like this:

 $result_leados = "INSERT INTO tb_usuarios(email) VALUES ('$email')";

In addition, it is not possible to send email through gmail using the Host as "localhost". Correct would be:

$mail->Host = 'smtp.gmail.com';

Finally, see if your account gmail is configured to send email through Websites/Apps.
Log into the account of google and visit this link to see if it is enabled: https://myaccount.google.com/lesssecureapps

Finally, if you are still in trouble it may be something more specific. Here is another discussion with some good answers: Sending email via Phpmailer to Gmail

Browser other questions tagged

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