Giter Site home page Giter Site logo

Comments (15)

Synchro avatar Synchro commented on May 18, 2024

A syntax error on that means that you're not using PHP 8.2, but something very old that doesn't support namespaces, which were introduced in PHP 5.3. I suggest you write a script containing <?php phpinfo(); to double check your version.

from phpmailer.

DrWilliamHobbs avatar DrWilliamHobbs commented on May 18, 2024

Ive double checked it: Same as before....

PHP Version 8.2.12 Build Date Nov 25 2023 08:05:53

from phpmailer.

Synchro avatar Synchro commented on May 18, 2024

This isn't something specific to PHPMailer. Try seeing if PHP gives you an error if you ask it to run this:

<?php
use abc\xyz;

That's a simple use statement creating an alias for a non-existent class, but it should do nothing at all if you try to run it. If you run it on an old version of PHP, you should get the same error.

from phpmailer.

DrWilliamHobbs avatar DrWilliamHobbs commented on May 18, 2024

There is nothing and No errors.

from phpmailer.

Synchro avatar Synchro commented on May 18, 2024

OK, so now add the original lines back in, one at a time, until the problem starts happening.

from phpmailer.

XL-2000 avatar XL-2000 commented on May 18, 2024

My guess...

Switch the order of the "require" and "use" lines.
In your code you are using a namespace which is not available yet (since the loading of the files will happen AFTER the declaration.
I expect if you load the files before the "use", it should work (if the files are loaded properly)

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

from phpmailer.

Synchro avatar Synchro commented on May 18, 2024

No, that won't help. Use statements are just local aliases, the require statements have no effect on them. They only come into play when you instantiate a class.

from phpmailer.

DrWilliamHobbs avatar DrWilliamHobbs commented on May 18, 2024

OK, so now add the original lines back in, one at a time, until the problem starts happening.

theres is no change

My guess...

Switch the order of the "require" and "use" lines. In your code you are using a namespace which is not available yet (since the loading of the files will happen AFTER the declaration. I expect if you load the files before the "use", it should work (if the files are loaded properly)

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

same...

from phpmailer.

XL-2000 avatar XL-2000 commented on May 18, 2024

Two questions:

  1. Are you using <?php at the start of your PHP file, incase unsafe / shorthand tags (<?) are not allowed
  2. In case you are not providing the full code file, are you sure you are not using "use" inside a class declaration? Like:
class Foo { 
use PHPMailer\PHPMailer\PHPMailer;
}

it should be


use PHPMailer\PHPMailer\PHPMailer;
class Foo {
...
}

Maybe its good to provide you full file, since it seems to be a overall syntax error

from phpmailer.

DrWilliamHobbs avatar DrWilliamHobbs commented on May 18, 2024

Two questions:

1. Are you using `<?php` at the start of your PHP file, incase unsafe / shorthand tags (`<?`) are not allowed

2. In case you are not providing the full code file, are you sure you are **not** using "`use`" inside a class declaration? Like:
class Foo { 
use PHPMailer\PHPMailer\PHPMailer;
}

it should be


use PHPMailer\PHPMailer\PHPMailer;
class Foo {
...
}

Maybe its good to provide you full file, since it seems to be a overall syntax error

I'll check it on tuesday, because my files are in the office ^^

from phpmailer.

XL-2000 avatar XL-2000 commented on May 18, 2024

So, what's the verdict?

from phpmailer.

ucsendre avatar ucsendre commented on May 18, 2024

Hello,
I have the same problem: PHP Parse error: syntax error, unexpected token "use"
The code I try to use is:

<? function cleaninput($input) { $input = trim($input); $input = stripslashes($input); $input = htmlspecialchars($input); return $input;} if (isset($_POST['name']) && isset($_POST['email'])) { if (isset($_POST['name'])) { $felado = cleaninput( $_POST['name'] ); } else { $felado = ''; }; if (isset($_POST['email'])) { $faemail = cleaninput( $_POST['email'] ); } else { $faemail = ''; }; if (isset($_POST['subject'])) { $targy = cleaninput( $_POST['subject'] ); } else { $targy = ''; }; if (isset($_POST['message'])) { $uzenet = cleaninput( $_POST['message'] ); } else { $uzenet = ''; }; require 'inc/Exception.php'; require 'inc/PHPMailer.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); try { $mail->setLanguage('hu', 'inc/language/'); $mail->setFrom('[email protected]', $felado); $mail->addAddress('[email protected]', 'Someone'); $mail->addReplyTo($faemail, $felado); $mail->isHTML(true); $mail->Subject = 'Üzenet a weboldalról'; $mail->Body = 'Tárgy: <strong>' . $targy . '</strong><br/>Üzenet:<br/>' . $uzenet; $mail->AltBody = $uzenet; $mail->send(); $vissza = '<div id="form-message-success" class="mb-4">Üzenetét továbbítottuk.</div>'; } catch (Exception $e) { $vissza = "<div id='form-message-warning' class='mb-4'>Az üzenet küldése sikertelen. Hibaüzenet: {$mail->ErrorInfo}</div>"; }; }; header("Location: https://somedomain.hu/"); exit;

from phpmailer.

XL-2000 avatar XL-2000 commented on May 18, 2024

And what happens when you put the "use" and "require" lines on the top of your file, so as the first lines?

<?php
require ...
use...

from phpmailer.

ucsendre avatar ucsendre commented on May 18, 2024

And what happens when you put the "use" and "require" lines on the top of your file, so as the first lines?

<?php
require ...
use...

It seems this works.
Thank you!
:)

from phpmailer.

XL-2000 avatar XL-2000 commented on May 18, 2024

And what happens when you put the "use" and "require" lines on the top of your file, so as the first lines?

<?php
require ...
use...

It seems this works. Thank you! :)

You're welcome!
That was what I was saying all along!
"Use" is handled compile-time, not run-time.
I guess TS has the same problem

from phpmailer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.