phpmailer causes syntax error error, Unexpected T_FUNCTION when hosted

Asked

Viewed 897 times

-1

Well I have a problem in phpmailer I am using a XAMPP server to mess with it I made a form but it is sending normally to my email that in case it would be GMAIL however I have a hosting on the localweb and when I put my site in the air and fill mine 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 am not using this file follows my PHP code and an excerpt from the form of my site:

THE 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: It is worth remembering that this is working perfectly local with xampp only when I upload the project to the web it stops working. And I also created my own email domain on the localweb where my email goes there and is redirected to my gmail account

  • 1

    Your local xampp php may differ from the hosted server php. some other things of hosting may be disabled smtp,email port 587 various other problems.

  • I’ll take a look here

  • 1

    I don’t think it’s a DOOR problem... The weird thing is that it should fix the problem: if (version_compare(PHP_VERSION, '5.3.0', '<')) {, I really don’t know why this is happening, what version of your server?

  • the serividor xampp Voce says ? if it is and version 3.2.2

  • Xampp is not a package of programs and is not official PHP, it is only a facilitator, it can have more than one version of php, what I want to know is the version of php installed in the hosting @Kirito - Creates a script called info.php and puts this content <?php echo phpinfo(); and then run and find out where the version says and let me know.

  • so man and this is the version PHP Version 5.6.15

  • There seems to be no problem with what you presented. Remember that the PHP compiler can point out the error in a "wrong" line when there are errors if () else. Usually when there’s a { or ( open. It may also be the lack of the line delimiter ; at some point in the scripts before the line pointed to by the error. The error may not even be in the Phpmailier codes. You should create breakpoints by searching for logical points to eliminate the possibility of errors until you find the location.

Show 2 more comments

2 answers

1


Log in to class.phpmailer.php and go to line 3040 and replace the code with this.

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 configuration code that I use on my server and works right.

    $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;
  • appeared the following error: Mail error: SMTP Connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

  • in a few moments I’m putting the site back on the air if you want you can even make a test on it so you can take a look at the error that

  • 1

    @Kirito now this problem has something related to smtp. which smtp will use?

  • and so I’m using a domain of my own that I would be [email protected] access it via Webmail but from there it automatically redirects to my gmail account because my client wants to receive via gmail

  • soon my smtp can not be gmail and without tecmovgruas maybe that’s the mistake I will check here and I warn you already

  • friend tested with this smtp: smpt.tecmovgruas.com and gave this error Mail error: SMTP error: The address§of the following destination failed: [email protected]: Recipient address Rejected: Access Denied

  • @kirito You have to use smtp.gmail you use that google service you create custom domain over use gmail inbox ? this is just a mask plus the domain point as gmail smtp. so it is important to use gmail smtp

  • then because from what I saw it worked more gmail blocked something like this because the email goes to Webmail in the case contact enter Webmail and my client prefer so soon if the email goes to Webmail the vorreto would not be using web mail smtp ?

  • I updated my post in php so that you can see the editions that reduced this new error

  • 1

    You can sort it out, but this is more of a gambit, the real thing if (version_compare(PHP_VERSION, '5.3.0', '<')) { should solve the problem. If the error is occurring with the if there is something else wrong, we have to look for the source of the problem. It must be something else.

  • 1

    @Kirito tries to use port 465

  • TSL even or mute to SSL

  • @Kirito tries the 2

  • ssl gives the same error that I last mentioned and tsl keeps endlessly loading the page until it expires

  • I think I found problem... the smtp from Ocaweb to email with her.. you cannot change the (from) of ... the from has to be the same as the smtp login user.

  • from has to be coming from the same domain as this contact

  • http://wiki.locaweb.com/pt-br/Email_Locaweb_-_Envio_Autenticado

  • funcionouuuuuuuuuu friend thank you so much for your help

Show 13 more comments

1

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

<?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";


    } 

}
?>

Browser other questions tagged

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