Jump to content

Email Query


Recommended Posts


This is just hard to explain. I'm coding a help desk. I have right now 4 different email meassages in my database. I would like to send out an email message automatically based on what the user does. For instance, If a new user would like to sign up I want to send out the email message in the database name user-new user signup.

So my thoughts were to include the variables from the form being submitted in the email messages that are located in the database. Pull the message out of the database and mail the message using PHPmail function in the processing script file.

That doesn't work. The delimna is to get the information from the form and put it in the email that's going to be sent out to the user.

If you can think of a better way to do this your help is greatly appreciated. Some code is below.

This is one of the messages in the database:

mssql_query("INSERT INTO email(email_name, subject, email) VALUES ('User-New User Signup', 'Keiser Support - User Information',
'Thank you for signing up with Keiser Support. Please review your user information below: <br><br>
User Information: <br>
User Name:'$e_user'<br>
First Name:'$first'<br>
Last Name:'$last'<br>
Email Address:'$email'<br>

If any of your user information is incorrect you can log into Keiser Support and edit your account.<br>
Please do not respond to this email this is an unmonitored email address. Keep this information for your records.<br><br>
Keiser Support Team<br>')");


[B]This is the processing script for the new user page:[/B]

//Next...Moving on to connecting to the database
$connect=mssql_connect($server, $username, $password);
mssql_select_db($db, $connect);

//assigning variables


//error messages
if(strlen($user) == 0)
header("Location: http://webdemo/newusernameerr.html");
if(strlen($email) == 0)
header("Location: http://webdemo/newuseremailerr.html");
if(strlen($user)== 0 && strlen($email)==0)
header("Location: http://webdemo/newusercomberror.html");
//querying database
$sql="SELECT username
FROM info
WHERE username = '$user'";

$result = mssql_query($sql)
            or die('result not added');
//inserting name, email, password, and location into the database if it's not already there
if(!mssql_num_rows($result) == $user)
    //insert values into the database
    $query = "INSERT INTO info (username, password, firstname, lastname, email, phone, location) VALUES ('$user', '$newpass', '$first', '$last', '$email', '$ph', '$loc')";
  //add values to database by using mssql_query
  mssql_query($query) or die('Error, insert query failed');
$sql="SELECT email FROM email WHERE id=1";

$result = mssql_query($sql)
            or die('Query failed. ');

for ($i=0; $i < mssql_num_rows($result); $i++) {

$sql="SELECT subject FROM email WHERE id=0";

$result = mssql_query($sql)
            or die('Query failed. ');

for ($i=0; $i < mssql_num_rows($result); $i++) {

  //intializing session variable
  foreach($HTTP_POST_VARS as $key=>$value)
    //intializing mail varables
  $to = stripslashes($_POST['email']);
  $from ="KCSIT@Keisercollege.edu"; 
  if(mail($to, $subject, $body, "From: $from")){
  header("Location: http://webdemo/thankyou.php");}
  else{ header("Location: http://webdemo/failedmailerr.html");}
header("Location: http://webdemo/user_nmerror.html");
Link to comment
Share on other sites

you will probably either want to do an eval() on your email field (will need just a little more than eval-ing it, but it's a direction) -- but this can be risky.

otherwise, you can do a str_replace("{username}",$username,$email); type of code for each replacement value.
Link to comment
Share on other sites

If you must store your email in SQL Server, just go ahead and have SQL server mail it for you.  Pass in the variables into a function or SP and mail it using the DBmail SP.  For pre-2005 I think it was called SQLMail.

I think the call is "sp_send_dbmail" and you can find the parameters online.  Just google it.

The benefit would be that you could actually have this set up as a trigger on your Users table so it would fire off an email on insert and you would never have to worry about it again.
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.