Ir para conteúdo
Fórum Script Brasil
  • 0

problema phpmailer


TNT

Pergunta

Olá a todos. Pretendo colocar um formulário de contato em meu site e para isso estou usando a classe phpmailer. Testei no servidor local e tudo funcionou perfeitamente. Porém, quando coloquei no servidor web o script simplesmente não faz nada, a tela fica branca. Gostaria de saber se o servidor precisa ter alguma configuração ou permissão especial para que se rode o script. Abaixo o código que estou utilizando:

<html>
<head>
<title>Meu formulário!</title>
</head>
<body>


<?php

//error_reporting(E_ALL);
//error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$nome=$_POST['nome'];
$email=$_POST['email'];
$assunto=$_POST['assunto'];
$mensagem=$_POST['mensagem'];

$body = "Nome: " . $nome . "<br>Email: " . $email . "<br><br>Mensagem: <br>" . $mensagem;

$mail             = new PHPMailer();


$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "remetente@email.com";  // GMAIL username
$mail->Password   = "senha";            // GMAIL password

$mail->SetFrom('$email', '$nome');

$mail->AddReplyTo("$email","$nome");

$mail->Subject    = $assunto;

//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "destinatario@email.com";
$mail->AddAddress($address, "Meu Nome");


if(!$mail->Send()) {
  echo "Erro no envio da mensagem: " . $mail->ErrorInfo;
} else {
  echo "<script>alert(\"Mensagem enviada com sucesso!\")</script>";
}

?>

</body>
</html>

Obrigado

Editado por TNT
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Experimente

<?php

error_reporting( E_ALL & ~E_NOTICE );

require_once('PHPMailer_v5.0.0/class.phpmailer.php');

list($nome, $email, $mensagem) = array('URSACAO','URSOLOUCO@MSN.COM','HELLO WORD!');

$assunto            = 'Teste de envio de e-mail! Servidor do google';
$body               = "Nome: " . $nome . "<br>Email: " . $email . "<br><br>Mensagem: <br>" . $mensagem;
$mail               = new PHPMailer();
$mail->IsSMTP();                                // telling the class to use SMTP
$mail->SMTPDebug    = 2;                        // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                       // enable SMTP authentication
//$mail->SMTPSecure = "ssl";                      // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";           // sets GMAIL as the SMTP server
$mail->Port       = 465;                        // set the SMTP port for the GMAIL server
$mail->Username   = "USUARIO@gmail.com";   // GMAIL username
$mail->Password   = "SENHA_GMAIL";                   // GMAIL password

$mail->SetFrom('$email', '$nome');

$mail->AddReplyTo("$email","$nome");

$mail->Subject    = $assunto;
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "USUARIO@DOMINIO.COM";
$mail->AddAddress($address, "Meu Nome");

if(!$mail->Send()) {
  echo "Erro no envio da mensagem: " . $mail->ErrorInfo;
} else {
  echo "<script>alert(\"Mensagem enviada com sucesso!\")</script>";
}

?>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...