Jump to content

Send an email action


lukeawade

Recommended Posts

I have a registration page that inserts information to my database and I'm trying to send an email with some additional information to the person who registered but I cant figure it out.

 

Here is what I have. Not sure where to add the email code.

<?php require_once('Connections/connRegistration.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['reg_id'], "int"),
                       GetSQLValueString($_POST['proj_id'], "int"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['company'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "int"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['cell_phone'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['discipline'], "text"),
                       GetSQLValueString($_POST['registration_date'], "date"),
                       GetSQLValueString($_POST['ip'], "text"),
                       GetSQLValueString($_POST['distribution_method'], "text"));

  mysql_select_db($database_connRegistration, $connRegistration);
  $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error());
}

?>

Link to comment
Share on other sites

I tried that but maybe I'm not putting in the right information.

<?php
// Your email address
$email = GetSQLValueString($_POST['email'], "text");
// The subject
$subject = "Enter your subject here";
// The message
$message = "Enter your message here";
mail($email, $subject, $message, "From: admin@test.com");?>

Link to comment
Share on other sites

What type of email address are you sending it?

 

If it is Yahoo, AOL, or Hotmail, they tend to not accept emails from a lot of php scripts without valid headers, or where servers who do not ping back that they have a mail server on them...

Link to comment
Share on other sites

Any help with this is appreciated.

 

I am using the code below and it isnt sending an email.

<?php require_once('Connections/connRegistration.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['reg_id'], "int"),
                       GetSQLValueString($_POST['proj_id'], "int"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['company'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "int"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['cell_phone'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['discipline'], "text"),
                       GetSQLValueString($_POST['registration_date'], "date"),
                       GetSQLValueString($_POST['ip'], "text"),
                       GetSQLValueString($_POST['distribution_method'], "text"));

  $email = $_POST['email'];
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers .= 'From: admin@m-repro.com' "\r\n";
  mail ("$email", 'Statement for', "Thank You!", $headers);

  mysql_select_db($database_connRegistration, $connRegistration);
  $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error());
}
?>

Link to comment
Share on other sites

I figured out this works.

<?php  $email = $_POST['email'];
  $fname = $_POST['first_name'];
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers .= 'From: admin@m-repro.com' . "\r\n";
  mail("$email",'MySmartPlans Registration', "$fname, \n\nThank you for registering.", $headers);?>

 

But the problem is sometimes I get like 5 or 6 of the same email in a row and the \n\n doesnt send the Thank You to another line. How do I make the HTML work?

Link to comment
Share on other sites

I figured out why I am getting the same email a bunch of times. Its putting in my database more than once. Why is it doing that? Here is what I have? Also still need to know how to make HTML work like \n.

 

<?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['reg_id'], "int"),
                       GetSQLValueString($_POST['proj_id'], "int"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['company'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "int"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['cell_phone'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['discipline'], "text"),
                       GetSQLValueString($_POST['registration_date'], "date"),
                       GetSQLValueString($_POST['ip'], "text"),
                       GetSQLValueString($_POST['distribution_method'], "text"));
  
  $email = $_POST['email'];
  $fname = $_POST['first_name'];
  $serial = $_POST['cell_phone'];
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers .= 'From: MySmartPlans Registration <admin@m-repro.com>' . "\r\n";
  mail("$email",'MySmartPlans Registration', 
       "$fname, 
           \nThank you for registering for MySmartPlans. Put in your Serial Number below to your MySmartPlans.
	   \nSerial Number: $serial
	   \nIf you have any issues please call 816-221-7881.", 
   $headers);

  mysql_select_db($database_connRegistration, $connRegistration);
  $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error());
}?>

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.