Jump to content

[SOLVED] Email on Activation


dare87

Recommended Posts

I am trying to make is so that when an account is activated it will send an email out but I don't know where to put the code. Here is what I have.

 

<?php
// Include the PHP script that contains the session information.
include('../includes/session_admin.php');

// Get the user id from the URL.
$id = $_GET['id'];

// Connect to the database.
require_once ('../../../loumysql_connect.php');

// Set up the query.
$query = "UPDATE users SET active=NULL WHERE user_id=$id";

// Run the query.
$results = @mysql_query ($query);

// Reload the page.
$url = '../user_review.php';
header("Location: $url");

?>

 

Here is the code that I need added... but I don't know where and/or what I may be missing

 

<?php
$query =  "SELECT first_name, last_name, email FROM users WHERE user_id=$id";

// Send the email.
$headers = "From: \"Admin\" < noreply >\r\n";
$headers .= "Reply-To: noreply\r\n";
$body = "$first_name $last_name,\n";
$body .= "You account has been activated.\n\n";
$body .= "Admin";
mail($email, 'Account Activation', $body, $headers)

?>

 

Thanks for the help

Link to comment
Share on other sites

I can't really tell you where the code would be going without seeing what's actually happening on those includes.

 

Just put the mail code where you want the action to be. Most likely before the header() function is called.

Link to comment
Share on other sites

I tried this and got an unexpected T_VARIABLE error

 

<?php
// Include the PHP script that contains the session information.
include('../includes/session_admin.php');

// Get the user id from the URL.
$id = $_GET['id'];

// Connect to the database.
require_once ('../../../loumysql_connect.php');

// Set up the query.
$query = "UPDATE users SET active=NULL WHERE user_id=$id";

// Run the query.
$results = @mysql_query ($query);

// Set up the query.
$query =  "SELECT first_name, last_name, email FROM users WHERE user_id=$id";
// Run the query.
$results = @mysql_query ($query);

// Send the email.
$headers = "From: \"Blah\" < noreply@Blah.com >\r\n";
$headers .= "Reply-To: noreply@Blah.com\r\n";
$body = "$first_name $last_name,\n";
$body .= "You account has been activated.\n\n";
$body .= "Blah.com";
mail($email, 'Registration Confirmation', $body, $headers)


// Reload the page.
$url = '../user_review.php';
header("Location: $url");

?>

 

As for what the include..

 

session_admin.php is just a protection, makes it so you have to have access level 0 to access the page.

Link to comment
Share on other sites

I'm not quite sure I understand the reasoning for this query:

 

// Set up the query.
$query = "UPDATE users SET active=NULL WHERE user_id=$id";

 

If this is just a default.. then you can set the default value in the MySQL table (it appears to be a default setting you want anyway, don't know why you'd set it to NULL on the fly for any other reason)

 

.. anyway ..

 

It doesn't appear you're actually initializing $email to ever be anything, thus when you call mail(), it's not being sent to anywhere but a blank variable.

Link to comment
Share on other sites

The reason the account needs to be activated is because the site requires payment before you can login. I want to setup paypal ipn, but I cant get it working.

 

For the time being there is a person taking phone calls and when they have recieved a credit card payment, the rep will then activate the account.

 

What I am trying to do is make it so when the account is activated it sends the user an email telling them so.

 

I tried this and it still didn't send the email.

 

<?php
// Include the PHP script that contains the session information.
include('../includes/session_admin.php');

// Get the user id from the URL.
$id = $_GET['id'];

// Connect to the database.
require_once ('../../../loumysql_connect.php');

// Set up the query.
$query = "UPDATE users SET active=NULL WHERE user_id=$id";

// Run the query.
$results = @mysql_query ($query);

// Set up the query.
$query =  "SELECT first_name, last_name, email FROM users WHERE user_id=$id";
// Run the query.
$results = @mysql_query ($query);

if (mysql_affected_rows() == 1) { // If it ran OK.

// Send the email.
$headers = "From: \"blah\" < noreply@blah.com >\r\n";
$headers .= "Reply-To: noreply@blah.com\r\n";
$body = "$first_name $last_name,\n";
$body .= "You account has been activated.\n\n";
$body .= "blah.com";
mail($email, 'Registration Confirmation', $body, $headers);

} else {
echo '  Account could not be activated. We apologize for any inconvenience.'; 
	}

// Reload the page.
$url = '../user_review.php';
header("Location: $url");

?>

Link to comment
Share on other sites

change

<?php
if (mysql_affected_rows() == 1) { // If it ran OK.

// Send the email.
$headers = "From: \"blah\" < noreply@blah.com >\r\n";
$headers .= "Reply-To: noreply@blah.com\r\n";
$body = "$first_name $last_name,\n";
$body .= "You account has been activated.\n\n";
$body .= "blah.com";
mail($email, 'Registration Confirmation', $body, $headers);

} else {
echo '  Account could not be activated. We apologize for any inconvenience.'; 
	}
?>

 

to

<?php
while ($row = mysql_fetch_assoc($result))
{
// Send the email.
$headers = "From: \"blah\" < noreply@blah.com >\r\n";
$headers .= "Reply-To: noreply@blah.com\r\n";
$body = "{$row['first_name']} {$row['last_name']},\n";
$body .= "You account has been activated.\n\n";
$body .= "blah.com";
mail($row['email'], 'Registration Confirmation', $body, $headers);

}?>

Link to comment
Share on other sites

This is the code...

<?php
// Include the PHP script that contains the session information.
include('../includes/session_admin.php');

// Get the user id from the URL.
$id = $_GET['id'];

// Connect to the database.
require_once ('../../../loumysql_connect.php');

// Set up the query.
$query = "UPDATE users SET active=NULL WHERE user_id=$id";

// Run the query.
$results = @mysql_query ($query);

// Set up the query.
$query =  "SELECT first_name, last_name, email FROM users WHERE user_id=$id";
// Run the query.
$results = @mysql_query ($query);

while ($row = mysql_fetch_assoc($result))
{
// Send the email.
$headers = "From: \"blah\" < noreply@blah.com >\r\n";
$headers .= "Reply-To: noreply@blah.com\r\n";
$body = "{$row['first_name']} {$row['last_name']},\n";
$body .= "You account has been activated.\n\n";
$body .= "blah.com";
mail($row['email'], 'Registration Confirmation', $body, $headers);

}

// Reload the page.
$url = '../user_review.php';
header("Location: $url");

?>

 

This is the error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/lou/auxiliary/user_activate.php on line 22

 

LINE 22 (while ($row = mysql_fetch_assoc($result)))

 

Warning: Cannot modify header information - headers already sent by (output started at /public_html/lou/auxiliary/user_activate.php:22) in /public_html/lou/auxiliary/user_activate.php on line 36

 

LINE 36 (header("Location: $url");)

 

Link to comment
Share on other sites

Please don't take this the wrong way... but I don't know a lot about php. I use books and ask for help. I am trying to learn just like everyone else.

 

If you know how to fix it please inform me but please don't be mean about it.

 

thanks

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.