tombob10 Posted June 3, 2012 Share Posted June 3, 2012 Hi, I have a written a registration script which enters the information into the db and sets MD5 and reports errors like duplicate emails. However I am completely stuck on how to integrate an email notification into it. Does anyone know how to do this or point me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/ Share on other sites More sharing options...
freelance84 Posted June 3, 2012 Share Posted June 3, 2012 php mailer class is a pretty standard option to send emails: http://phpmailer.worxware.com/ Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350838 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 <?php $actName = "Word"; $actPass = "pa$$word"; // Send the registration e-mail $to = $email; // Send email to our user $subject = 'Registration Information'; // Give the email a subject $message = ' Your Registration Information: -------------------------- Username: '.$actName.' Password: '.$actPass.' -------------------------- Congratulations, this is just random junk. '; // Our message above including the link $headers = 'From:[email protected]' . "\r\n"; // Set from headers mail($to, $subject, $message, $headers); // Send our email ?> Using mail() to send the email... give it a go and tweak it to your needs as you want. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350869 Share on other sites More sharing options...
justlukeyou Posted June 3, 2012 Share Posted June 3, 2012 Thanks for that, it comes with the following error Cannot modify header information - headers already sent by (output started at /home/ukhomefu/public_html/users/register.php:1) Does this mean the user should be redicrected to the homepage? header("Location: index.php"); Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350875 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 Yes that's what it's doing, you can only redirect once so I'd suggest moving the redirect to after the mail has been sent. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350878 Share on other sites More sharing options...
justlukeyou Posted June 3, 2012 Share Posted June 3, 2012 Thanks, I have put the redirect after the email like so, it generates the error four time, do I need to put anything on the index.php page? '; // Our message above including the link $headers = 'From:[email protected]' . "\r\n"; // Set from headers mail($to, $subject, $message, $headers); // Send our email ?> <?php header("Location: index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350884 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 I don't know the code that index.php consists of so I can't really help you blindly guessing... But the issue is the headers can only be sent once, the way I have my custom registration setup is that the page is it's own entity and performs no redirect and just displays a typical thank you for registering and check your email message. Clearer: There is an HTML form that a user fills out to register The HTML form sends the information to say register.php register.php takes the information and does whatever it needs with it and displays a status message upon completion Also, don't go editing the existing code unless you back it up so you can revert all changes you've made! Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350891 Share on other sites More sharing options...
justlukeyou Posted June 3, 2012 Share Posted June 3, 2012 Thanks, It creates the following error Cannot modify header information - headers already sent by (output started at /home/ukhomefu/public_html/users/register.php:1 for the following 3 lines of code. Firstly I'm not sure what the first two do. The page wont redirect also. Does the index page need some form of code to receive redirect and does it need to be access the dbase? setcookie("user", mysql_insert_id(), $time); setcookie("pass", mysql_real_escape_string(md5($password)), $time); header("Location: index.php"); Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350895 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 setcookie("user", mysql_insert_id(), $time); setcookie("pass", mysql_real_escape_string(md5($password)), $time); header("Location: index.php"); 1st line - sets a cookie to store the user 2nd line - sets a cookie to store the pass These are just for creating a session, the cookies are used to "remember" the user that is logged in. 3rd line - this is the redirect sending the user to the index.php page once the session has been created. You could just remove the 3rd line and display a thank you for registering type of message and providing a link to the index.php, or if the navigation menu is displayed no link is needed. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350897 Share on other sites More sharing options...
justlukeyou Posted June 3, 2012 Share Posted June 3, 2012 Hi, I found something which says all the code should be at the top and without any white space. That is what generally creates this error. So I shall ahve to go through all that. Cannot modify header information - headers already sent by (output started at /home/ukhomefu/public_html/users/register.php:1) Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350900 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 Yes, headers have to be sent before any output is displayed to the browser! Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350903 Share on other sites More sharing options...
justlukeyou Posted June 3, 2012 Share Posted June 3, 2012 Thanks, I see , this part here. So from the top I should have my db access code, then all the headers. $headers = "From: ".$website['name']." Is it very sensitive. I have removed all the website I can see but it still creates the errors. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350906 Share on other sites More sharing options...
Skewled Posted June 3, 2012 Share Posted June 3, 2012 That's how it works! Just make sure no output is done before the redirect, and that pesky error will go away and you should be well on your way to sending registration e-mails. The script for the site is sensitive in nature? I understand that completely! Let me know if it works out! Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1350908 Share on other sites More sharing options...
tombob10 Posted June 4, 2012 Author Share Posted June 4, 2012 Hi, It does respond and send the email but it generates the errors at the top of the page. headers already sent by (output started at /home/site/public_html/users/register.php:1) I have the code directly underneath the connect code and I tried to remove all the white space possible but the error still appears. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1351122 Share on other sites More sharing options...
Skewled Posted June 4, 2012 Share Posted June 4, 2012 That's excellent, go to the main php help forum here and read the HEADERS post and you'll see what your doing wrong.. it's explained really well there in that post. Quote Link to comment https://forums.phpfreaks.com/topic/263583-email-notification-for-registration-script/#findComment-1351143 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.