No I have not token API from mailtrap yet
and this the place that I got them from
okay… so… when you put it into your PHP script, you’re putting your ACTUAL password, right? Not *******2966 ?
I’m assuming it’s *'ing out the first part of your actual password.
In the PHP script I am putting this: SMTP_PASSWORD = ‘********2966’;
is that wrong? if it is wrong than please show the right one. I have been working on it for almost a week.
Well i assume it’s their thing masking the password. If it’s not…
What happens if you take that, exactly as it is, paste it into your script, set $phpmailer->Subject = "Test"; $phpmail->Body = "Testing"; $phpmailer->send();
, does it put an email in your sandbox mailbox?
When I run that in google chrome and I write my email to reset my password it gives me this problem: Error #2: stream_socket_client(): Unable to connect to ssl://sandbox.smtp.mailtrap.iolive.smtp.mailtrap.io2525 (Failed to parse address "sandbox.smtp.mailtrap.iolive.smtp.mailtrap.io2525") [C:\xampp\htdocs\cms\vendor\phpmailer\phpmailer\src\SMTP.php line 420]
it tells me that the problem is in line 420 as you can see, and this is the whole code in there: $connection = stream_socket_client(
$host . ‘sandbox.smtp.mailtrap.io’ .
$port,
$errno,
$errstr,
$timeout,
STREAM_CLIENT_CONNECT,
$socket_context
);
and line 420 is: $host . ‘sandbox.smtp.mailtrap.io’.
ssl://sandbox.smtp.mailtrap.iolive.smtp.mailtrap.io2525
Where’s it getting the other half of that server string? Somewhere it’s picking up the live server’s address.
wait…
are… you modifying the phpmailer source code directly???
Don’t do that. Dont touch the phpmailer source files. Revert it to the original.
No I have not worked in phpmailer files yet but in google chrome it gives me that error and I have this function in smtp.php: public function connect($host, $port = null, $timeout = 30, $options = )
{
//Clear errors to avoid confusion
$this->setError(‘’);
//Make sure we are not connected
if ($this->connected()) {
//Already connected, generate error
$this->setError(‘Already connected to a server’);
return false;
}
if (empty($port)) {
$port = self::DEFAULT_PORT;
}
//Connect to the SMTP server
$this->edebug(
"Connection: opening to $host:$port, timeout=$timeout, options=" .
(count($options) > 0 ? var_export($options, true) : 'array()'),
self::DEBUG_CONNECTION
);
$this->smtp_conn = $this->getSMTPConnection($host, $port, $timeout, $options);
if ($this->smtp_conn === false) {
//Error info already set inside `getSMTPConnection()`
return false;
}
$this->edebug('Connection: opened', self::DEBUG_CONNECTION);
//Get any announcement
$this->last_reply = $this->get_lines();
$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
$responseCode = (int)substr($this->last_reply, 0, 3);
if ($responseCode === 220) {
return true;
}
//Anything other than a 220 response means something went wrong
//RFC 5321 says the server will wait for us to send a QUIT in response to a 554 error
//https://www.rfc-editor.org/rfc/rfc5321#section-3.1
if ($responseCode === 554) {
$this->quit();
}
//This will handle 421 responses which may not wait for a QUIT (e.g. if the server is being shut down)
$this->edebug('Connection: closing due to error', self::DEBUG_CONNECTION);
$this->close();
return false;
}
where $host and $posrt equal null
This is you, in a phpmailer file, making a change in the incorrect manner, and causing your problems.
Anything inside the \vendor\phpmailer directory is off limits for you to modify. Restore it to its original form.
how to do that?
I have not worked with that yet and I do not know about it at all I have not touched any of the phpmailer directory file. please just help me to do that right.
So where did you get phpmailer to start with?
So the best way to revert to the original state would be to run rm -rf vendor/
followed by composer install
.
I did run mr -rf vendor followed by composer install but it is giving me this code: PS C:\xampp\htdocs\cms> rm -rf vendor/
Remove-Item : A parameter cannot be found that matches parameter name
‘rf’.
At line:1 char:4
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], Paramet
erBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell
.Commands.RemoveItemCommand
PS C:\xampp\htdocs\cms> composer install
Composer could not detect the root package (nasratullah/cms) version, defaulting to ‘1.0.0’. See https://getcomposer.org/root-version
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the composer fund
command to find out more!
PS C:\xampp\htdocs\cms>
and it is not working in the browser as well I mean it is still giving me the same problem as the last time
Delete C:\xampp\htdocs\cms\vendor and then run the composer install again.
Should I delete the vendor folder? or what?
I deleted the vendor folder once than I run the composer install it installed the vendor folder again for me and gave me this code: PS C:\xampp\htdocs\cms> rm -rf vendor/
Remove-Item : A parameter cannot be found that matches parameter name
‘rf’.
At line:1 char:4
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], Paramet
erBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell
.Commands.RemoveItemCommand
PS C:\xampp\htdocs\cms> composer install
Composer could not detect the root package (nasratullah/cms) version, defaulting to ‘1.0.0’. See https://getcomposer.org/root-version
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 updates, 0 removals
composer fund
command to find out more!What isn’t working? What is the error you are seeing?
It is not sending the email and this is the error that I am seeing: 2024-12-04 08:19:05 Connection: opening to ssl://live.smtp.mailtrap.io:2525, timeout=300, options=array()
2024-12-04 08:19:06 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:1408F10B:SSL routines:ssl3_get_record:wrong version number [C:\xampp\htdocs\cms\vendor\phpmailer\phpmailer\src\SMTP.php line 413]
2024-12-04 08:19:06 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [C:\xampp\htdocs\cms\vendor\phpmailer\phpmailer\src\SMTP.php line 413]
2024-12-04 08:19:06 Connection failed. Error #2: stream_socket_client(): Unable to connect to ssl://live.smtp.mailtrap.io:2525 (Unknown error) [C:\xampp\htdocs\cms\vendor\phpmailer\phpmailer\src\SMTP.php line 413]
2024-12-04 08:19:06 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
NOT SENT
You should be using port 465 rather than 2525
The page he’s referencing (Post 22) to says to use 2525.
The error response seems to be indicating that either the server’s SSL version is wrong, or the server isn’t using TLS and you’re trying to tell it to use TLS.
What does your current mail send code look like?
This is my current email sending code: <?php
use PHPMailer\PHPMailer\PHPMailer;
require DIR . ‘./vendor/autoload.php’;
require ‘./classes/Config.php’;
if (!ifItIsMethod(‘get’) && !$_GET[‘forgot’]) {
redirect(‘index’);
}
if (ifItIsMethod(‘post’)) {
if (isset($_POST[‘email’])) {
$email = $_POST[‘email’];
$length = 50;
$token = bin2hex(openssl_random_pseudo_bytes($length));
if (email_exists($email)) {
if ($stmt = mysqli_prepare($connection, "UPDATE users SET token='{$token}' WHERE user_email = ?")) {
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
/**
*
* configure PHPMailer
*
*/
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = Config::SMTP_HOST;
$mail->Port = Config::SMTP_PORT;
$mail->Username = Config::SMTP_USER;
$mail->Password = Config::SMTP_PASSWORD;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //This is equivalent to "ssl". If you're expecting TLS, this should be ENCRYPTION_STARTTLS
$mail->SMTPAuth = true; // Not valid, should be a boolean.
$mail->isHTML(true); //true, but message doesnt contain HTML.
$mail->SMTPDebug = 3; //Showing all messages from both sides.
$mail->setFrom('nasratullahkhadim00@gmail.com', 'Nasratullah Khadim');
$mail->addAddress($email);
$mail->Subject = 'This is a test email';
$mail->Body = 'Email body';
if ($mail->send()) {
echo "IT WAS SENT";
} else {
echo "NOT SENT";
}
}
}
}
}