Rullings Posted March 18, 2012 Share Posted March 18, 2012 Hello. I have this login form that works, however, i would like to add a notification email to be sent to me when a new user is registered trough the form. Thanks alot for your time guys. Here is the code for my register page. <?php session_start(); $bruker = strtolower($_POST['brukernavn']); $brukernavn = strip_tags($bruker); $passord = strip_tags(substr($_POST['passord1'],0,32)); $cleanPassord = crypt($passord,$bruker); $navn = strip_tags($_POST['navn']); $epost = $_POST['epost']; $aktivert = 'nei'; setcookie("brukernavn", $bruker, time()+3600); setcookie("navn", $navn, time()+3600); setcookie("epost", $epost, time()+3600); include_once '../securimage/securimage.php'; $securimage = new Securimage(); $spam=false; if ($securimage->check($_POST['captcha_code']) == false) { $spam=true; } else { ///////////Bildeopplastning: //Maks størrelse i kb define ("MAX_SIZE","30000"); //30mb //Ser om filen er ett bildet function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; $bildefeil=0; //Ser om bildet er valgt if(isset($_POST['registrer'])) { $image=$_FILES['image']['name']; //Hvis bildet eksisterer if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); //(små bokstaver) if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $bildefeil=1; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { $bildefeil=2; $errors=1; } //teller bilder allerede opplastet, og gir nytt navn til bildet basert på bilde antall. $directory = "../brukerbilder/"; if (glob($directory . "*.".$extension) != false) { $filecount = count(glob($directory . "*.".$extension)); $image_name='bilde'.$filecount.'.'.$extension; }else{ $filecount = 0; //Første bildet av denne typen (eks. jpg, gif, png...) $image_name='bilde'.$filecount.'.'.$extension; } //echo "filecount: ".$filecount."<br/>"; //gir nytt navn og hvor det skal lagres $newname="../brukerbilder/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { $bildefeil=3; $errors=1; }}} } //Hvis ingen feil if(isset($_POST['registrer']) && !$errors) { //Bildet er lastet opp } ///////////Registrering til DB: include('mysqlconnect.php'); $passord1 = $_POST['passord1']; $passord2 = $_POST['passord2']; $feilmelding='none'; if ($passord1!=$passord2) $feilmelding=1; if (!isset($_POST['godkjenning'])) $feilmelding=2; if ($feilmelding=='none') { $count=mysql_query("SELECT * FROM brukere"); $id = mysql_num_rows($count); $poeng = 100; $post = mysql_real_escape_string($epost); $query = "SELECT * FROM brukere WHERE epost='$post';"; $resultat = mysql_query($query); if (mysql_num_rows($resultat) > 0) { // Emailen eksisterer $feilmelding=3; } else { // Emailen eksisterer ikke $name = mysql_real_escape_string($brukernavn); $query = "SELECT * FROM brukere WHERE brukernavn='$name';"; $resultat = mysql_query($query); if (mysql_num_rows($resultat) > 0) { // Brukeren eksisterer $feilmelding=4; } else { // Brukeren eksisterer ikke $result = mysql_query("SELECT * FROM brukere"); while($row = mysql_fetch_array($result)) { if ($row['brukernavn']=='ingen') $browseID=$row['browseID']; } if (($browseID+10)>$id) $browseID=0; else $browseID+=10; mysql_query("UPDATE brukere SET browseID = '".$browseID."' WHERE id = 0"); $query="INSERT INTO brukere ( id, passord, brukernavn, fornavn, epost, bilde, poeng, poengTotal, browseID, aktivert) VALUES ( '".$id."', '".mysql_real_escape_string($cleanPassord)."', '".mysql_real_escape_string($brukernavn)."', '".mysql_real_escape_string($fornavn)."', '".mysql_real_escape_string($epost)."', '".mysql_real_escape_string($image_name)."', '".mysql_real_escape_string($poeng)."', '".mysql_real_escape_string($poeng)."', '".mysql_real_escape_string($browseID)."', '".mysql_real_escape_string($aktivert)."' )"; if (!mysql_query($query)) $feilmelding=5; else { $to = $epost; $subject = "Aktivering av konto for ".$brukernavn.""; $message = " Velkommen som ny supertrafikkbruker!\n\n Brukernavn: ".$brukernavn."\n Passord: ".$_POST['passord1']."\n\n Klikk på lenken under for å aktivere kontoen:\n http://www.formastic.com/browser/browser_system/phpfunksjoner/aktivering.php?hash=".$cleanPassord."&&brukernavn=".$brukernavn."\n (Hvis lenken ikke er aktiv, kopier og aktiver lenken i adressefeltet.) "; $from = "contact@formastic.com"; $headers = "Fra:" . $from; mail($to,$subject,$message,$headers); } } } } } echo '<meta http-equiv="Refresh" content="0; url=../../registrer.php?registrert=true&&feilmelding='.$feilmelding.'&&bildefeil='.$bildefeil.'&&spam='.$spam.'&&brukernavn='.$bruker.'&&epost='.$epost.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/ Share on other sites More sharing options...
AyKay47 Posted March 18, 2012 Share Posted March 18, 2012 So use the mail function to send yourself an email. Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328669 Share on other sites More sharing options...
downah Posted March 18, 2012 Share Posted March 18, 2012 $to = "youremail@email.com"; $subject = "New member"; $name_field = $_POST['namefield'] $email_field = $_POST['emailfield']; //constructing the message $body = " User: $name_field\n\n E-Mail: $email_field\n\n"; // ...and away we go! mail($to, $subject, $body); Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328737 Share on other sites More sharing options...
Rullings Posted March 18, 2012 Author Share Posted March 18, 2012 $to = "youremail@email.com"; $subject = "New member"; $name_field = $_POST['namefield']; $email_field = $_POST['emailfield']; //constructing the message $body = " User: $name_field\n\n E-Mail: $email_field\n\n"; // ...and away we go! mail($to, $subject, $body); Thank you, that sends me an email, however, the mail is blank with only User: and E-Mail: lines inside, no username or email tho. Im sorry to bother you guys, but my php is kinda limited and i am just plain stupid sometimes :] Here is my code now, after adding the above kode. <?php session_start(); $bruker = strtolower($_POST['brukernavn']); $brukernavn = strip_tags($bruker); $passord = strip_tags(substr($_POST['passord1'],0,32)); $cleanPassord = crypt($passord,$bruker); $navn = strip_tags($_POST['navn']); $epost = $_POST['epost']; $aktivert = 'nei'; setcookie("brukernavn", $bruker, time()+3600); setcookie("navn", $navn, time()+3600); setcookie("epost", $epost, time()+3600); include_once '../securimage/securimage.php'; $securimage = new Securimage(); $spam=false; if ($securimage->check($_POST['captcha_code']) == false) { $spam=true; } else { ///////////Bildeopplastning: //Maks størrelse i kb define ("MAX_SIZE","30000"); //30mb //Ser om filen er ett bildet function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; $bildefeil=0; //Ser om bildet er valgt if(isset($_POST['registrer'])) { $image=$_FILES['image']['name']; //Hvis bildet eksisterer if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); //(små bokstaver) if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $bildefeil=1; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { $bildefeil=2; $errors=1; } //teller bilder allerede opplastet, og gir nytt navn til bildet basert på bilde antall. $directory = "../brukerbilder/"; if (glob($directory . "*.".$extension) != false) { $filecount = count(glob($directory . "*.".$extension)); $image_name='bilde'.$filecount.'.'.$extension; }else{ $filecount = 0; //Første bildet av denne typen (eks. jpg, gif, png...) $image_name='bilde'.$filecount.'.'.$extension; } //echo "filecount: ".$filecount."<br/>"; //gir nytt navn og hvor det skal lagres $newname="../brukerbilder/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { $bildefeil=3; $errors=1; }}} } //Hvis ingen feil if(isset($_POST['registrer']) && !$errors) { //Bildet er lastet opp } ///////////Registrering til DB: include('mysqlconnect.php'); $passord1 = $_POST['passord1']; $passord2 = $_POST['passord2']; $feilmelding='none'; if ($passord1!=$passord2) $feilmelding=1; if (!isset($_POST['godkjenning'])) $feilmelding=2; if ($feilmelding=='none') { $count=mysql_query("SELECT * FROM brukere"); $id = mysql_num_rows($count); $poeng = 100; $post = mysql_real_escape_string($epost); $query = "SELECT * FROM brukere WHERE epost='$post';"; $resultat = mysql_query($query); if (mysql_num_rows($resultat) > 0) { // Emailen eksisterer $feilmelding=3; } else { // Emailen eksisterer ikke $name = mysql_real_escape_string($brukernavn); $query = "SELECT * FROM brukere WHERE brukernavn='$name';"; $resultat = mysql_query($query); if (mysql_num_rows($resultat) > 0) { // Brukeren eksisterer $feilmelding=4; } else { // Brukeren eksisterer ikke $result = mysql_query("SELECT * FROM brukere"); while($row = mysql_fetch_array($result)) { if ($row['brukernavn']=='ingen') $browseID=$row['browseID']; } if (($browseID+10)>$id) $browseID=0; else $browseID+=10; mysql_query("UPDATE brukere SET browseID = '".$browseID."' WHERE id = 0"); $query="INSERT INTO brukere ( id, passord, brukernavn, fornavn, epost, bilde, poeng, poengTotal, browseID, aktivert) VALUES ( '".$id."', '".mysql_real_escape_string($cleanPassord)."', '".mysql_real_escape_string($brukernavn)."', '".mysql_real_escape_string($fornavn)."', '".mysql_real_escape_string($epost)."', '".mysql_real_escape_string($image_name)."', '".mysql_real_escape_string($poeng)."', '".mysql_real_escape_string($poeng)."', '".mysql_real_escape_string($browseID)."', '".mysql_real_escape_string($aktivert)."' )"; if (!mysql_query($query)) $feilmelding=5; else { $to = $epost; $subject = "Aktivering av konto for ".$brukernavn.""; $message = " Velkommen som ny supertrafikkbruker!\n\n Brukernavn: ".$brukernavn."\n Passord: ".$_POST['passord1']."\n\n Klikk på lenken under for å aktivere kontoen:\n http://www.formastic.com/browser/browser_system/phpfunksjoner/aktivering.php?hash=".$cleanPassord."&&brukernavn=".$brukernavn."\n (Hvis lenken ikke er aktiv, kopier og aktiver lenken i adressefeltet.) "; $from = "contact@formastic.com"; $headers = "Fra:" . $from; mail($to,$subject,$message,$headers); $to = "contact@formastic.com"; $subject = "New member"; $name_field = $_POST['namefield']; $email_field = $_POST['emailfield']; //constructing the message $body = " User: $name_field\n\n E-Mail: $email_field\n\n"; // ...and away we go! mail($to, $subject, $body); } } } } } echo '<meta http-equiv="Refresh" content="0; url=../../registrer.php?registrert=true&&feilmelding='.$feilmelding.'&&bildefeil='.$bildefeil.'&&spam='.$spam.'&&brukernavn='.$bruker.'&&epost='.$epost.'">'; ?> Thanks for your time, yet again Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328775 Share on other sites More sharing options...
SaCH Posted March 18, 2012 Share Posted March 18, 2012 can you post your html form code here ? Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328804 Share on other sites More sharing options...
guinbRo Posted March 18, 2012 Share Posted March 18, 2012 You need to modify the variables in the example downah gave you. You simply copied and pasted it into your code. Right above it, it looks like the original script's author use's the mail function. Just copy his and tweak it so it gets sent to you with the user's name and email. Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328844 Share on other sites More sharing options...
Rullings Posted March 19, 2012 Author Share Posted March 19, 2012 You need to modify the variables in the example downah gave you. You simply copied and pasted it into your code. Right above it, it looks like the original script's author use's the mail function. Just copy his and tweak it so it gets sent to you with the user's name and email. I figured it out.. Damn it... My email did not work, so i tried another one. Now it works. Spanks and thanks to everyone. Quote Link to comment https://forums.phpfreaks.com/topic/259173-email-sent-to-admin-when-a-new-user-is-registered/#findComment-1328878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.