If I add this $mail->SMTPDebug = 2; or this one $mail->SMTPDebug = 1; it tells me this:2024-11-30 18:22:42 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
NOT SENT
and the port is: 465.
It does not really matter if I write there 2525 or 465 in both manners it gives the same problem. And which is the gmail’s SMTP relay host could you tell me please.
Well it does matter if the server you’re connecting to doesnt open 2525 as a port.
If you’re trying to use mailtrap as a sending service, you’d need to give the specific server and port that they specify. I dont know where you got the sandbox server name, but from their documentation here:
It looks like the server should be either bulk or live, their recommended port is 587 (according to their screenshot, they dont open 465. Which… means yes, it does matter…), your username should be api, and the password should be the API key you generated.
If you’re using a different guide from mailtrap, i’d need to know where.
I don’t know if this helps, but I made a comment about the port?
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
So all of those lines are doing nothing… If i cut out all of the unused lines, your code is currently this:
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //This is equivalent to "ssl". If you're expecting TLS, this should be ENCRYPTION_STARTTLS
$mail->SMTPAuth = 'PLAIN'; // 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';
At first I got things from a php course which I am learning by the way and the teacher is Edwin Diaz but those things did not work so I got them from mailtrap and these are also not working so what should I do?