LaFougère
New member
Im trying to do an email verification to register to my website but the mail is not sending when i click the button to send the form
Im using SMTP2GO but because my script dont work, im not sure about how to use it.
Here is the script:
PS: Im french, i hope my english isn't too bad
Im using SMTP2GO but because my script dont work, im not sure about how to use it.
Here is the script:
PHP:
require 'vendor/autoload.php';
session_start();
try {
$bdd = new PDO('mysql:host=127.0.0.1;dbname=users;charset=utf8;', 'admin', 'donotlookthere:)');
} catch (Exception $e) {
die('Erreur : ' . $e->getMessage());
}
if (isset($_POST['envoi'])) {
$prenom = htmlspecialchars($_POST['prenom']);
$nom = htmlspecialchars($_POST['nom']);
$email = htmlspecialchars($_POST['mail']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT, ['cost' => 12]);
$password_confirm = password_hash($_POST['password_confirm'], PASSWORD_DEFAULT);
$checkEmail = $bdd->prepare("SELECT * FROM users WHERE email = ?");
$checkEmail->execute(array($email));
$cle = rand(100000000000, 999999999999);
if ($checkEmail->rowCount() > 0) {
$error_message = "Email déjà utilisé.";
} elseif ($_POST['password'] !== $_POST['password_confirm']) {
$error_message = "Les mots de passe ne correspondent pas.";
} else {
$insertUser = $bdd->prepare("INSERT INTO users (prenom, nom, email, password, cle, confirm) VALUES (?, ?, ?, ?, ?, ?)");
$insertUser->execute(array($prenom, $nom, $email, $password, $cle, 0));
$recup_user = $bdd->prepare('SELECT * FROM users WHERE email = ?');
$recup_user->execute(array($email));
if($recup_user->rowCount() > 0) {
$user_info = $recup_user->fetch();
$_SESSION['id'] = $user_info['id'];
$_SESSION['prenom'] = $user_info['prenom'];
$_SESSION['nom'] = $user_info['nom'];
$_SESSION['email'] = $user_info['email'];
$_SESSION['password'] = $user_info['password'];
$_SESSION['cle'] = $user_info['cle'];
$_SESSION['confirm'] = $user_info['confirm'];
function smtpmailer($to, $from, $from_name, $subject, $body)
{
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Host = 'mail.smtp2go.com'; // Hôte SMTP2GO
$mail->Port = 2525; // Port SMTP2GO (2525, 587, ou 465)
$mail->Username = 'teamgeek.fr'; // Nom d'utilisateur SMTP2GO
$mail->Password = 'donotlookthere:)'; // Mot de passe SMTP2GO
$mail->setFrom($from, $from_name);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->Send();
}
$to = $email;
$from = 'nepasrepondre.superannales.bia@teamgeek.fr';
$name = 'Super Annales BIA';
$subj = 'Vérification de votre adresse email';
$msg = 'Cliquez sur ce lien pour confirmer votre adresse email: https://teamgeek.fr/annales-bia/verify.php?email='.$email.'&cle='.$cle;
smtpmailer($to, $from, $name, $subj, $msg);
}
}
}
PS: Im french, i hope my english isn't too bad