phpMailer causes error syntax error, unexpected T_FUNCTION when hosted [closed]

0
Well I'm having a problem with phpMailer I'm using a XAMPP server to be able to mess with it I made a form but it is normally sending to my email, which in the case would be GMAIL, however I have a web site hosting and when I put my website in the air and fill in my form it gives the following error:

Parse error: syntax error, unexpected T_FUNCTION in /home/storage/1/8e/5d/tecmovgruas2/public_html/phpmailer/class.phpmailer.php on line 3040

code snippet of line 3040 that appears in error:

 protected function clearQueuedAddresses($kind)
    {
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
            $RecipientsQueue = $this->RecipientsQueue;
            foreach ($RecipientsQueue as $address => $params) {
                if ($params[0] == $kind) {
                    unset($this->RecipientsQueue[$address]);
                }
            }
        } else {
            $this->RecipientsQueue = array_filter(
                $this->RecipientsQueue,
                function ($params) use ($kind) {
                    return $params[0] != $kind;
                });
        }
    }

Remember that I'm not using this file, it follows my PHP code and an excerpt from my site's form:

HTML:

<form id="main-contact-form1" name="contact-form" action="envio.php" method="post">
                <div class="row  wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
                  <div class="col-sm-6">
                    <div class="form-group">
                      <input type="text" name="name" class="form-control" placeholder="Nome" required="required">
                    </div>
                  </div>
                  <div class="col-sm-6">
                    <div class="form-group">
                      <input type="email" name="email" class="form-control" placeholder="E-mail" required="required">
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <input type="text" name="subject" class="form-control" placeholder="Assunto" required="required">
                </div>
                <div class="form-group">
                  <textarea name="message" id="message" class="form-control" rows="4" placeholder="Escreva sua Mensagem" required="required"></textarea>
                </div>                        
                <div class="form-group">
                  <button type="submit" class="btn-submit">Enviar</button>
                </div>
              </form>   

PHP:

     <?php
$Nome       = $_POST["name"];   // Pega o valor do campo Nome
$Email       = $_POST["email"];   // Pega o valor do campo Telefone
$Assunto      = $_POST["subject"];  // Pega o valor do campo Email
$Mensagem   = $_POST["message"];   // Pega os valores do campo Mensagem

// Variável que junta os valores acima e monta o corpo do email

$Vai        = "Nome: $Nome\n\nE-mail: $Email\n\nAssunto: $Assunto\n\nMensagem: $Mensagem\n";
/*date_default_timezone_set('Etc/UTC');
*/
require("phpmailer/PHPMailerAutoload.php");
require("phpmailer/class.smtp.php");

define('GUSER', '[email protected]');   // <-- Insira aqui o seu GMail
define('GPWD', 'lalala');        // <-- Insira aqui a senha do seu GMail

function smtpmailer($para, $de, $de_nome, $assunto, $corpo) { 
    global $error;
    $mail = new PHPMailer();
    $mail->setLanguage('pt');
    $mail->IsSMTP();        // Ativar SMTP
    $mail->SMTPDebug = 0;       // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
    $mail->SMTPAuth = true;     // Autenticação ativada
    $mail->SMTPSecure = 'tsl';  // SSL REQUERIDO pelo GMail
    $mail->Host = 'smtp.tecmovgruas.com'; // SMTP utilizado
    $mail->Port = 587;          // A porta 587 deverá estar aberta em seu servidor
    $mail->Username = GUSER;
    $mail->Password = GPWD;
    $mail->SetFrom($de, $de_nome);
    $mail->Subject = $assunto;
    $mail->Body = $corpo;
    $mail->AddAddress($para);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Mensagem enviada!';
        return true;
    }
}

// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER), 

 if (smtpmailer('[email protected]', '[email protected]', 'renata', 'Assunto do Email', $Vai)) {

    Header("location:obrigado.html"); // Redireciona para uma página de obrigado.

}
if (!empty($error)) echo $error;
?>

Note that this is working perfectly locally with xampp only when I upload the project to the web it stops working. And also I created a proper email domain by localweb where my emails go to ee redirected to my account gmail

    
asked by anonymous 15.02.2016 / 19:00

2 answers

1

Enter the class.phpmailer.php file and go to line 3040 and replace the code with that.

protected function clearQueuedAddresses($kind)
{
    //if (version_compare(PHP_VERSION, '5.3.0', '<')) {
        $RecipientsQueue = $this->RecipientsQueue;
        foreach ($RecipientsQueue as $address => $params) {
            if ($params[0] == $kind) {
                unset($this->RecipientsQueue[$address]);
            }
        }
    //} else {
    //    $this->RecipientsQueue = array_filter(
    //        $this->RecipientsQueue,
    //        function ($params) use ($kind) {
    //            return $params[0] != $kind;
    //        });
    //}
}

My setup code that I use on my server works fine.

    $this->mail->isSMTP();
        $this->mail->CharSet = 'UTF-8';
        $this->mail->SMTPDebug = false;
        $this->mail->Host = 'smtp.gmail.com';
        $this->mail->Port = 587;
        $this->mail->SMTPSecure = 'tls';
        $this->mail->SMTPAuth = true;
    
15.02.2016 / 19:33
1

For Locaweb , I usually use this code and it works well, if you want to try it out:

<?php

if(@$_POST['acao'] == 'envia'){
    $empresa = mysqli_real_escape_string($conexao, $_POST['empresa']);
    $nome = mysqli_real_escape_string($conexao, $_POST['nome']);


    require_once('PHPMailer-master/PHPMailerAutoload.php');


    $mail = new PHPMailer();



    $caixaPostalServidorEmail='[email protected]';
    $caixaPostalServidorSenha='suasenhadoemail'; // SE USAR $mail->SMTPAuth  = true; 
    // $caixaPostalServidorSenha='suasenhadoemail'; // Comente para não autenticar $mail->SMTPAuth  = false; 

    $caixaPostalServidorNome='[email protected]';

    $enviaFormularioParaEmail='[email protected]';
    $enviaFormularioParaNome='Cliente';

    $assunto = "Novo Email";
    $assunto = "$assunto";


    $mensagemConcatenada ="<h2 style='font-family:Verdana, Geneva, sans-serif'>Contato do site</h2>
    <hr>
    <strong>Empresa:</strong> $empresa<br />
    <strong>Nome:</strong> $nome<br /> ";

    $mail->IsSMTP();
    $mail->SMTPAuth  = true; //false para não autenticar
    $mail->Charset   = 'utf8_decode()';
    $mail->Host  = 'smtp.'.substr(strstr($caixaPostalServidorEmail, '@'), 1);
    $mail->Port  = '587';
    $mail->Username  = $caixaPostalServidorEmail;
    $mail->Password  = $caixaPostalServidorSenha;
    $mail->From  = $caixaPostalServidorEmail;
    $mail->FromName  = utf8_decode($caixaPostalServidorNome);
    $mail->IsHTML(true);
    $mail->Subject  = utf8_decode($assunto);
    $mail->Body  = utf8_decode($mensagemConcatenada);


    $mail->AddAddress($enviaFormularioParaEmail,utf8_decode($enviaFormularioParaNome));

    if(!$mail->Send()){
    $mensagemRetorno = 'Erro ao enviar formulário: '. print($mail->ErrorInfo);
    }else{  


    echo"Mensagem enviada";


    } 

}
?>
    
15.02.2016 / 19:28