dare87 Posted May 5, 2008 Share Posted May 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/ Share on other sites More sharing options...
gijew Posted May 5, 2008 Share Posted May 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533513 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533519 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 there is a missing ; which cause the error, but it did not send the email. any ideas Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533522 Share on other sites More sharing options...
MadTechie Posted May 5, 2008 Share Posted May 5, 2008 mail($email, 'Registration Confirmation', $body, $headers); <--add the ; Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533528 Share on other sites More sharing options...
southofsomewhere Posted May 5, 2008 Share Posted May 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533530 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533533 Share on other sites More sharing options...
southofsomewhere Posted May 5, 2008 Share Posted May 5, 2008 .. are you reading the responses .. ? $email isn't being initialized anywhere that I can see.. Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533534 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 that is what i thought this if (mysql_affected_rows() == 1) { // If it ran OK. would do. if it is not, how do i do it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533537 Share on other sites More sharing options...
southofsomewhere Posted May 5, 2008 Share Posted May 5, 2008 What I'm trying to say is.. for the.. 3rd time.. is that the email address is never set, initialized, declared, given a value .. so when you call mail().. the email is being sent.. to.. no one. Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533541 Share on other sites More sharing options...
MadTechie Posted May 5, 2008 Share Posted May 5, 2008 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); }?> Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533546 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 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") Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533551 Share on other sites More sharing options...
southofsomewhere Posted May 5, 2008 Share Posted May 5, 2008 You're.. seriously not even trying at this point. You're calling the row assoc on $result when the variable is $results Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533552 Share on other sites More sharing options...
dare87 Posted May 5, 2008 Author Share Posted May 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533556 Share on other sites More sharing options...
MadTechie Posted May 5, 2008 Share Posted May 5, 2008 update while ($row = mysql_fetch_assoc($result)) to while ($row = mysql_fetch_assoc($results)) note the s on $results, my fault really Quote Link to comment https://forums.phpfreaks.com/topic/104212-solved-email-on-activation/#findComment-533571 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.