error sending confirmation email: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php require_once(__DIR__ . '/sendEmails/vendor/autoload.php'); $dbHost = 'localhost'; $dbName = 'ecommerce_store'; $dbUser = 'root'; $dbPass = ''; try { $pdo = new PDO("mysql:host=$dbHost;dbname=$dbName", $dbUser, $dbPass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); exit; } $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; // hash the password using bcrypt $hashedPassword = password_hash($password, PASSWORD_BCRYPT); // insert the user data into the database $stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (:name, :email, :password)"); $stmt->execute(['name' => $name, 'email' => $email, 'password' => $hashedPassword]); if ($stmt->rowCount() > 0) { // send confirmation email to the user $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; // SMTP server $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'ggcobani@gmail.com'; // SMTP username $mail->Password = 'GENERATED_APP_PASSWORD'; // SMTP password $mail->setFrom('gcobani.mkontwana@agilelimitless.org.za', 'Our Site Team'); $mail->addAddress($email, $name); // Add a recipient $mail->Subject = 'Registration Confirmation'; $mail->Body = "Dear $name,\n\nThank you for registering at our site. Your account has been created, and you can now log in using your email address and password.\n\nBest regards,\nOur Site Team"; if ($mail->send()) { echo 'success'; } else { echo 'error sending confirmation email: ' . $mail->ErrorInfo; } } else { echo 'error inserting user into database'; } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)