Localhost XAMPP phpmailer configuration not working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Localhost XAMPP phpmailer configuration not working

Postby Epiales » 15. May 2018 00:10

It's been awhile since I've actually created websites and used mail. I've recently taken on a huge responsibility to a very huge project and having to relearn many things. Like transferring from mysqli to PDO, as well as now the phpmailer. Since XAMPP doesn't have sendmail anymore that I can see from my recent download and installation, I've never used the phpmailer, and everything I do says that the mail sends, but I never receive an email at all. If anyone could help, it would be great.

Code to php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP=localhost
; http://php.net/smtp-port
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com--- I have changed this to be only my gmail email without the my-gmail-.... and with that... either way it made no difference
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail_path = "C:\xampp\htdocs\mysite\includes\PHPMailer\src\PHPMailer.php" --- I have made the link look like the one above as well and either way it makes no difference.

; For Win32 only.
;http://php.net/sendmail-from -- I have uncommented this line as well and either way it made no difference.
sendmail_from = admin@mywebsite.com


PHP function to send the mail:

Code: Select all
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;   ----------------------  I have tried  putting the use inside the function and I get errors if I do.
use PHPMailer\PHPMailer\SMTP;  ----------------------  I have tried  putting the use inside the function and I get errors if I do.
use PHPMailer\PHPMailer\Exception;  ----------------------  I have tried  putting the use inside the function and I get errors if I do.

function send_code($code, $email) {
 
// 'PHPMailer' here actually is the original folder 'PHPMailer-master'
// from unpacking the downloaded file PHPMailer-master.zip
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);

$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mygmail@gmail.com';
$mail->Password = 'mypass';
$mail->SMTPSecure = 'tls';

$mail->Port = 587;

$mail->setFrom('admin@mywebsite.com', 'Admin');
$mail->addAddress($email);
$mail->isHTML(true);

$mail->Subject = 'Confirmation Code';
$mail->Body = "Thank you for registering, your confirmation code is: ".$code;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   echo 'Message has been sent';
    }
}
?>


As I said, it says the message has been sent, but for two days now I can't seem to get an email. What am I doing wrong? I have also stopped the service and restarted after every change. I know that's a common mistake, so I make sure to do that. It also sends users information to the database, so I can't figure out why it's not sending mail :( :( :(

Thank you in advance, and blessings to all.
Last edited by Epiales on 15. May 2018 00:58, edited 2 times in total.
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10

Re: Localhost XAMPP phpmailer configuration not working

Postby Epiales » 15. May 2018 00:20

Just as a quick reply. For some reason it opens up the phpmailer.php in a text document every time I try and send mail too? LOL, what's up with that? Grrrrr

Be Blessed!
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 68 guests