-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need Help #2313
Comments
Without any in-depth views on your code, I see some things wrong here....
|
I can't see any of those screen shots. Please post code and error messages as text, not images. Please make sure you've read the instructions on how to load PHPMailer. |
|
What do you mean with step 3? Where should i put the PHPMailer Folder in? |
It still wont work... |
You shouldn't. Learn how to use composer and it will worry about that for you. |
|
It will work, but convention, and all the PHPMailer docs and examples, put If your |
If i load the page, the whole page wont work. My INDEX is iin test and the PHPMailer is in test/PHPMailer/src/ |
Any fatal error messages will be in your web sever's error log. If you're writing PHP, you need to know where that is. |
You could try adding this to the beginning of your script, before the requires: ini_set('display_errors', true);
error_reporting(E_ALL); But be sure to remove them in production. |
Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in /var/www/html/team/test/index.php:13 Stack trace: #0 {main} thrown in /var/www/html/team/test/index.php on line 13 |
Please post your actual code. |
Now, the site is loading... and loading... <?php
ini_set('display_errors', true);
error_reporting(E_ALL);
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
?>
<!DOCTYPE html>
<html lang="de">
<head>
<title>PHP SMPT Mailer</title>
</head>
<body>
<?php
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.google.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'mymail'; //SMTP username
$mail->Password = 'mypw'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); //Add a recipient
$mail->addAddress('[email protected]'); //Name is optional
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
<form method="POST" action="index.php">
<button type="submit" name="submit">COOOL</button>
</form>
</body>
</html> |
This code will attempt to send a message every time you load the page. If your hosting provider blocks outbound SMTP (as many do), you will likely have to wait for SMTP's 10-minute timeout period to expire before the script will continue. This is addressed in the troubleshooting guide, including tests to help you diagnose it. Setting |
I built a little form now with executing the mail stuff. But the site is still loading the whooooole time |
And now after removing SMTPDebug i've got that error: |
Sigh. The same SMTPDebug output that would show you what's happening... Re-enable it and post the output here. |
Bro now im not getting an error, but i dont receive the email |
Show the debug output. It will show you the SMTP transaction whether it's successful or not. |
SMTP::DEBUG_CONNECTION right? |
Yeah, invalid user or password. Im at yandex |
I don't know how many times I need to say this, but POST YOUR DEBUG OUTPUT. |
First, thank you for your help bro. Im from germany okay xD The output:
|
You are connecting to the wrong server to send through gmail (though you said you're sending through Yandex??). As in the gmail example provided, it should be:
|
Oops bro im sorry im using gmail in the example i sent you. |
You're connecting to the wrong port – should be 587, as per your script. Looks like gmail doesn't offer authentication on port 25, which is as expected. |
If im adding the variable Port, the whole site will loading |
My current Code: try { $mail->setFrom("[email protected]", "SparkySky.de"); $mail->Subject = "Test"; if($mail->send()){ |
So we are back to your host blocking it. Read their docs, see what they have to say about outbound SMTP. You could try:
though it's likely you'll have the same result. |
So i have to contact my host? |
Yes, or at least read their docs. This is usually a pretty common question, so they should document it. |
My host said that they're not blocking ports |
So do the tests to confirm that. They are all in the troubleshooting guide. You're not the first to have this kind of hosting problem. |
You are very, very unlikely to need to do that. It's very rare for cheap hosting to do any kind of egress blocking from within instances (their blocks will be implemented upstream, at the network level). Also SMTP uses TCP, not UDP. Find your problem before trying to fix it. Changing random things is unlikely to help, and if you do accidentally fix it, you won't know how or why. |
Now i've got this error: |
This is exactly what I mean by "changing random things". |
Hello. Im using Apache2 and wanna send some mails. But when i write "new PHPMailer()", i get an error, that the function would be undefined and the whole functions of PHPMailer wont work.
The code:
https://prnt.sc/11blkvv
Error:
https://prnt.sc/11bm6wu
The folder where PHPMailer is:
https://prnt.sc/11bllmd
The text was updated successfully, but these errors were encountered: