Jump to content

Archived

This topic is now archived and is closed to further replies.

misslilbit02

Email Query

Recommended Posts

Hi,

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>
-----------------------------------<br>
User Name:'$e_user'<br>
First Name:'$first'<br>
Last Name:'$last'<br>
Email Address:'$email'<br>
Location:'$loc'<br>
Password:'$newpass'<br><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>
Regards,<br>
Keiser Support Team<br>')");

mssql_close($connect);
?>

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


<?include('config.php');?>
<?php
session_start();
//Next...Moving on to connecting to the database
$connect=mssql_connect($server, $username, $password);
mssql_select_db($db, $connect);

//assigning variables

$user=$_POST['name'];
$first=$_POST['fname'];
$last=$_POST['lname'];
$email=$_POST['email'];
$ph=$_POST['phone'];
$loc=$_POST['location'];
$newpass=$_POST['password'];
$connew=$_POST['con_pass'];


//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++) {
  $body=mssql_result($result,$i,"email");
}

$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++) {
  $subject=mssql_result($result,$i,"subject");
}


  //intializing session variable
  foreach($HTTP_POST_VARS as $key=>$value)
{
  $thisData[$key]=$value;
  $_SESSION[$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");}
}
else
{
header("Location: http://webdemo/user_nmerror.html");
}
mssql_close($connect);
?>

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.