Jump to content

Email Notification for Registration Script


tombob10

Recommended Posts

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.

Link to comment
Share on other sites

<?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:webmaster@mydomain.com' . "\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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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:info@website.com' . "\r\n"; // Set from headers
mail($to, $subject, $message, $headers); // Send our email
?>

<?php
          header("Location: index.php");
?>

 

 

 

Link to comment
Share on other sites

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!  8)

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

           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.

Link to comment
Share on other sites

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)

 

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.