Created
September 8, 2014 20:55
-
-
Save kevinvavelin/d9b3d5d61cb140dbdf5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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