Jump to content

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
https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/
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.

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.

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

?>

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

}?>

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

 

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.