Skip to content

Instantly share code, notes, and snippets.

@kevinvavelin
Created September 8, 2014 20:55
Show Gist options
  • Save kevinvavelin/d9b3d5d61cb140dbdf5d to your computer and use it in GitHub Desktop.
Save kevinvavelin/d9b3d5d61cb140dbdf5d to your computer and use it in GitHub Desktop.
<?php
if(isset($_POST["mail"])) {
$mail = $_POST["mail"];
try {
$bdd = new PDO('mysql:host=votrehost;dbname=votrenomdebase', 'login', 'motdepasse');
} catch (Exception $e) {
die('Erreur : ' . $e->getMessage());
}
$mailExist = false;
$reponse = $bdd->query("SELECT * FROM mailing");
while ($donnees = $reponse->fetch())
{
$mailUser = $donnees["mail"];
if($mailUser == $mail)
{
$mailExist = true;
}
}
$reponse->closeCursor();
if($mailExist == false)
{
$hash = md5(rand(0,1000));
$requete = $bdd->exec("INSERT INTO mailing(mail,hash) VALUES ('$mail','$hash')");
$to = $mail;
$subject = "Vérification d'email";
$message = "Merci de vous être inscrit à la mailing list de MonProduit ! Pour terminer l'inscription veuillez cliquer sur le lien suivant : http://host.domain/verify.php?email=$mail&hash=$hash";
$header = "From:[email protected]\r\n";
mail($to, $subject, $message, $header);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment