Sending of SMTP Email

Asked

Viewed 103 times

1

I am sending and is going as sent, but I do not receive, what can be?

<?
/Leitura dos dados de cadastro
$nome = $_POST['nome'];
$empresa = $_POST['empresa'];
$telefone = $_POST['telefone'];
$email = $_POST['email'];
$mensagem = $_POST['mensagem'];

//mensagem do email
$dados = "<br><b>Contato Recebido:</b>";
$dados .= "<br><br>Nome: ".$nome."";
$dados .= "<br><br>Empresa: ".$empresa."";
$dados .= "<br><br>Telefone: ".$telefone."";
$dados .= "<br><br>Email: ".$email."";
$dados .= "<br><br>Mensagem: ".$mensagem."<br>";

//requisicao para phpmailer
if (!class_exists("phpmailer")) 
{
    require("PHPMailer-5.2.6/class.phpmailer.php");
}

 // Inicia a classe PHPMailer
 $mail = new PHPMailer();

$mail->IsSMTP(); //  Define que a mensagem será enviada via servidor SMTP
$mail->SMTPAuth = true; // Ativa a autenticação
$mail->SMTPSecure = "tls";  
$mail->CharSet = 'iso-8859-1';
$mail->IsHTML(true);
$mail->Host = 'mail.meudominio.com.br'; //endereço do servidor smtp
$mail->Port = 587;
$mail->Username = "[email protected]"; 
$mail->Password = "senha";

$mail->From = $email;
$mail->Subject = "Contato";  
$mail->MsgHTML($dados);
$address = "[email protected]"; 
$mail->AddAddress($address, "nome");


//envia
if($mail->Send())
{
    echo "enviado"; 
}else{ echo "erro"; }
?>
  • Did you check the junk mail? The address $address = "[email protected]"; is that correct? Are you testing on any host or locally? Add as many important details to the question.

  • It’s not in the junk mail. I’m testing it locally. $mail->Addaddress($address, "name"); that’s correct, already replaced by $mail->Addaddress("emaildestino");

  • 1

    Just a question for conscience, tried to change it <? for this reason <?php. Some servers see short_open_tag disabled.

  • 1

    Enabled the debug $mail->SMTPDebug = 3;, to see if something happens differently?

  • 1

    this comment above with a bar does not exist: /Leitura dos dados de cadastro, in addition to the use of short_open_tag is a bad practice.

  • The from should be an email from your domain and not passed by the user.

  • It would be good for you to see the error in the browser console, for example in Chrome. See if there are any errors.

Show 2 more comments

1 answer

0

Check that your server is enabled to send via SMTP.

For more doubt efficiency, tell us what kind of server you’re using.

Is using in environment Linux? Are you using some test server for Windows as Easyphp, XAAMP or similar?

With this information we can help better!

  • Thanks for the help, the error was actually in the 'from', which was getting a wrong parameter.

Browser other questions tagged

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