not submitting form via phpmailer

0

My problem is the following, I have a form on a html page and would like it to be sent by email , I did some research and decided to use > phpmailer , but when I click the send button nothing happens, it is disappointing. my form.

 <form class="formulario" action="enviar.php" method="post">
        <div class="form-group">
        <fieldset>

                <label for="nome">Nome</label>
            <input required name="nome" type="name" class="form-control" placeholder="Seu nome">
        </fieldset>
        </div>
        <div class="form-group">
        <fieldset>

            <label for="email">E-mail: </label>
            <input required name="email" type="email" class="form-control" placeholder="Seu email">
        </fieldset>
        </div>
        <div class="form-group">
        <fieldset>

            <label for="assunto">Assunto</label>
            <input required name="assunto" type="assunto" class="form-control" placeholder="Assunto do contato">
        </fieldset>
        </div>
        <div class="form-group">
        <fieldset>

            <label for="mensagem">Mensagem: </label>
            <textarea required name="mensagem" type="text" class="form-control" placeholder="Sua mensagem" rows="10" ></textarea>
        </fieldset>
        </div>
        <div class="form-group">
        <fieldset>
        <div class="form-group">
            <button type="submit" class="btn btn-default" name="enviar" value="enviar">Enviar</button>
        </fieldset>
  </div>  

File code submit.php is:

   <?php 

if (isset($_POST['enviar'])) {
$destinatarios = '[email protected]';
$nomeDestinatario = 'Contato formulario';
$usuario = '[email protected]'; 
$senha = 'SENHABLABLEBI'; 

/*abaixo as veriaveis principais, que devem conter em seu formulario*/ 

$nome = $_POST['nome'];
$assunto = $_POST['assunto'];
$_POST['mensagem'] = nl2br('E-mail: '. $_POST['email'] ." ". $_POST['mensagem']);

/*********************************** A PARTIR DAQUI NAO ALTERAR ************************************/ 

include_once("/phpmailer/PHPMailerAutoload.php");

$To = $destinatarios;
$Subject = $assunto;
$Message = $_POST['mensagem'];
$Host = 'mail.'.substr(strstr($usuario, '@'), 1);
$Username = $usuario;
$Password = $senha;
$Port = "587";
$mail = new PHPMailer();
$body = $Message;

$mail-> IsSMTP(); // telling the class to use SMTP

$mail-> Host = $Host; // SMTP server 

$mail-> SMTPDebug = 1; // enables SMTP debug information (for testing) 
// 1 = errors and messages 
// 2 = messages only 

$mail-> SMTPAuth = true; // enable SMTP authentication 

$mail-> Port = $Port; // set the SMTP port for the service server 

$mail-> Username = $Username; // account username 

$mail-> Password = $Password; // account password 

$mail-> SetFrom($usuario, $nomeDestinatario); 
$mail-> Subject = $Subject;
$mail-> MsgHTML($body);
$mail-> AddAddress($To, ""); 

if(!$mail-> Send()) 
{ 
$mensagemRetorno = 'Erro ao enviar e-mail: '. print($mail->ErrorInfo);
}
else 
{ 
$mensagemRetorno = 'E-mail enviado com sucesso!'; 
}
} ?>

The page is static and nothing happens nor error message appears, I thought it is the hosting that is not sending, I decided to test creating a file in php to send, however every time I squeeze it , e-mail is sent to me, I've tried it several times.

Code that sends the email at the time is:

    <?php
require '/phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = 'SENHABLABLEBI';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, 'ssl' also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('[email protected]', 'blabe');
$mail->addAddress('[email protected]');               // Name is optional

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'ASSUNTO BLABLE';
$mail->Body    = 'qualquer coisa bla bla blabla msgs';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>
    
asked by anonymous 22.04.2016 / 03:25

1 answer

0

Good morning expec,

Why do not you use the Mail function? link Mail Php

I find it simple and functional, so much that I've used it in a bulk emailing tool.

I hope I have helped.

    
22.04.2016 / 13:37