ryanwood4 Posted February 20, 2009 Share Posted February 20, 2009 When a user registers on my site, I would like to send them an email thanking them, and containing their username and password. Does anyone know of any codes that do this? Thanks. Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/ Share on other sites More sharing options...
shadiadiph Posted February 20, 2009 Share Posted February 20, 2009 try this <? $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password"]; header("Location: thankyou.php"); $to = "$email"; $subject = "$firstname Confirmation Of Your Inquiry At WEBSITE NAME"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>$firstname Your Inquiry</title> </head> <body> <table style='padding-left:0px' style='padding-top:0px'> <tr><td align='left'><img src='http://www.website.com/pix/logo.gif'></td></tr> </table> <table style='margin-left:12px'> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Dear $firstname $lastname,</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your inquiry has been received by WEBSITE NAME.</font></td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Username: $username</font></td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Password: $password</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Best Regards</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>WEBSITE NAME Team</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 11px' style='font-family: Tahoma, Arial'>This message has been automatically generated please do not reply.</font></td></tr> <tr><td> </td></tr> <tr><td> </td></tr> </table> <table style='margin-left:12px' style='margin-right:250px'> <tr><td><font style='color: #336699' style='font-size: 10px' style='font-family: Tahoma, Arial'>This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. If you have received this communication in error, please destroy this message. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity.</font></td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); exit; ?> I have used post for username and password but it is probably better to call them from the database first not to post them but i don't know about your database. You are probably better just adding the script above minus the $_POST values below your insert to database sql Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767078 Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Where and how would it be best to incorporate that into this? (Registration page) <?php // Connects to your Database mysql_connect("PRIVATE", "PRIVATE", "PRIVATE") or die(mysql_error()); mysql_select_db("PRIVATE") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['email'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the email is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $usercheck = $_POST['email']; $check = mysql_query("SELECT email FROM users WHERE email = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the email '.$_POST['email'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['email'] = addslashes($_POST['email']); } // now we insert it into the database $insert = "INSERT INTO users (email, password) VALUES ('".$_POST['email']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> or is it best to create a separate page. Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767080 Share on other sites More sharing options...
shadiadiph Posted February 20, 2009 Share Posted February 20, 2009 try this i usually submit all my form data to a second page that directs to thankyou or confirmation page. <?php // Connects to your Database mysql_connect("PRIVATE", "PRIVATE", "PRIVATE") or die(mysql_error()); mysql_select_db("PRIVATE") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['email'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the email is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $usercheck = $_POST['email']; $check = mysql_query("SELECT email FROM users WHERE email = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the email '.$_POST['email'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['email'] = addslashes($_POST['email']); } // now we insert it into the database $insert = "INSERT INTO users (email, password) VALUES ('".$_POST['email']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); $to = "$email"; $subject = "Confirmation Of Your Registration At WEBSITE NAME"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>Your Registration</title> </head> <body> <table style='padding-left:0px' style='padding-top:0px'> <tr><td align='left'><img src='http://www.website.com/pix/logo.gif'></td></tr> </table> <table style='margin-left:12px'> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your registration has been received by WEBSITE NAME.</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Username: $email</font></td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Your Password: $pass</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>Best Regards</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>WEBSITE NAME Team</font></td></tr> <tr><td> </td></tr> <tr><td><font style='font-size: 11px' style='font-family: Tahoma, Arial'>This message has been automatically generated please do not reply.</font></td></tr> <tr><td> </td></tr> <tr><td> </td></tr> </table> <table style='margin-left:12px' style='margin-right:250px'> <tr><td><font style='color: #336699' style='font-size: 10px' style='font-family: Tahoma, Arial'>This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. If you have received this communication in error, please destroy this message. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity.</font></td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767083 Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Thanks, but the emails don't seem to have been sent out? The code all looks fine, is there anything I need to change in it to make it function? Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767093 Share on other sites More sharing options...
shadiadiph Posted February 20, 2009 Share Posted February 20, 2009 yes sorry add this in $email = $_POST["email"]; $pass = $_POST["pass"]; $to = "$email"; $subject = "Confirmation Of Your Registration At WEBSITE NAME"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " sorry I didn't define $email or password just need to add the top two lines Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767101 Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Thanks so much, works perfectly! Cheers Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767109 Share on other sites More sharing options...
shadiadiph Posted February 20, 2009 Share Posted February 20, 2009 no problem Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767112 Share on other sites More sharing options...
shadiadiph Posted February 20, 2009 Share Posted February 20, 2009 add the same mail script again after it and change the top two lines of it to $to = "[email protected]"; $subject = "New User Registered At WEBSITE NAME"; and it will also send you a message saying someone has registered Link to comment https://forums.phpfreaks.com/topic/146118-solved-sending-an-email-when-user-registers/#findComment-767119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.