Jump to content

problems with using phpMail


Alith7

Recommended Posts

well, the phpMail script itself works fine, I'm trying to also post the info into a DB at the same time as running the mail script.

Is this even possible?

If so, how?

I've been fighting with it for days and am getting nowhere!

 

i have the mail script functioning, and a duplicate of the form that is only posting to the DB that works ok to.  I just can't seem to get them to work together.

 

I can post the scripts that I have so far if that would help.

 

Any help would be much appreciated!

Link to comment
Share on other sites

I'll attatch the files too if that helps.

 

Here's the Mail script which works great!

 

<?php
// set flag to indicate whether your variables have been sent
$mailSent = false;
$phoneconfirm = false;

if (array_key_exists('ewReg', $_POST)) {
// mail processing script
// remove escape characters from POST array
if (get_magic_quotes_gpc()) {
  function stripslashes_deep($value) {
	$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
	return $value;
	}
  $_POST = array_map('stripslashes_deep', $_POST);
  }
  
// validate the input beginning with name
$first_name = trim($_POST['first_name']);
if (empty($first_name)) {
	$error['first_name'] = 'Please enter your first name';
	}
$last_name = trim($_POST['last_name']);
if (empty($last_name)) {
	$error['last_name'] = 'Please enter your last name';
	}

// start validating entry beginning with checking the email field
// set variables to use in validating
$email = $_POST['email'];
$confirm = $_POST['confirm'];
$emailcheck = trim($_POST['email']);
$confirmcheck = trim($_POST['confirm']);

// check to see if the email was filled in
if (empty($emailcheck)) {
	// if no email check to see if there is a phone #
	$phone = trim($_POST['phone']);
	if (empty($phone)) {
		$error['phone'] = 'Please enter either a valid email or a phone number so that we can contact you if you win.';
		}
	elseif (empty($emailcheck) && !empty($phone)) {
		$phoneconfirm = true;
		}
	}
// if there is an email, first validate the email
elseif (!empty($emailcheck)) {
	// check for valid email address
	$pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
	if (!preg_match($pattern, trim($email))) {
 		$error['email'] = 'Please enter a valid email address';
  		}
	// compare email fields to make sure they match
	elseif ($emailcheck !== $confirmcheck) {
		$error['confirm'] = 'Your emails do not match.  Please check and make sure that your email is typed in correctly.';
		}
	// if everything checks out, send the email
	else {
		// send the email
		if (!isset($error)) {
			$mailSent = true;

			// Grab our config settings
			require_once("public_html/config.php");

			// Grab the FreakMailer class
			require_once("public_html/MailClass.inc");

			// instantiate the class
			$mailer = new RegMailer();

			// Change the "from" info from the default
			$mailer->FromName = 'Digital Edge Copy and Print centers';
			$mailer->From = 'info@digitaledgecc.com';

			// Change the Reply-to address from the default
			$mailer->AddReplyTo('info@digitaledgecc.com', 'Digital Edge Copy and Print centers');

			// Add an address to send to.
			$mailer->AddAddress('tashina@graphicedgeprinting.com', 'Tashina Meyer');

			//  Add Multiple Recipients each extra email needs it's own line
			$mailer->AddAddress("$email", "$first_name $last_name");

			// Set the subject
			$mailer->Subject = 'This is a test';

			// Add an attachment
			// $mailer->AddAttachment("images/10000.jpg", '10000.jpg');

			// Body
			$htmlBody = '<html>
			<head>
			<title>My HTML Email</title>
			</head>
			<body>
			<img src="http://www.phpfreaks.com/images/phpfreaks_logo.jpg" alt="PHP Freaks" /><br />
			<h2>PHP Freaks Rules!</h2>
			<p>We invite you to visit <a href="http://www.phpfreaks.com" title="PHP Freaks">PHP Freaks.com</a> for a loving community of PHP Developers who enjoy helping each other learn the language!</p>
			<p>Sincerely,<br />
			PHP Freaks Staff</p>'; 

			$textBody = 'My text-only body....
			NO HTML no fancy links
			nothing to spectacular'; 

			$mailer->Body = $htmlBody;
			$mailer->isHTML(true);
			$mailer->AltBody = $textBody;

			if(!$mailer->Send()) {
				$error['notSent'] = 'Sorry, there was a problem sending your registration. Please try again later.  If the problem persists, please contact the webmaster at bugs@digitaledgecc.com.';
				}
			$mailer->ClearAddresses();
			$mailer->ClearAttachments();
			}
		}	

	}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<link href="styles/basic.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="maincontent">

<?php if (isset($error['notSent'])) { ?>
<h1>Server Error</h1>
<p class="warning"><?php echo $error['notSent']; ?></p>
<?php } elseif ($mailSent) { ?>
<h1>Thank you for Registering</h1>
<p>You should recieve an email with your registration number and a special coupon just for you.  Please make sure that info@digitaledgecc.com is listed in your safelist so that your confirmation does not end up in junkmail.</p>
<?php } elseif ($phoneconfirm) { ?>
<h1>Thank you for Registering</h1>
<p>Please print this page with your registration number and keep it in a safe place.  You will need to present it as confirmation of identity if you win the drawing.  The link below will allow you to download and print a special grand opening coupon just for you.  You will need to present your coupon with your confirmation page in order to receive your discount.</p>
<?php } else { ?>

<?php if (isset($error['first_name'])) { ?><span class="warning"><?php echo $error['first_name']; ?><br /></span><?php } ?>
<?php if (isset($error['last_name'])) { ?><span class="warning"><?php echo $error['last_name']; ?><br /></span><?php } ?>
<?php if (isset($error['email'])) { ?><span class="warning"><?php echo $error['email']; ?><br /></span><?php } ?>
<?php if (isset($error['confirm'])) { ?><span class="warning"><?php echo $error['confirm']; ?><br /></span><?php } ?>
<?php if (isset($error['phone'])) { ?><span class="warning"><?php echo $error['phone']; ?><br /></span><?php } ?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="regForm" id="regForm">
<table width="450" border="0" cellspacing="0" cellpadding="1" align="center">
  <tr>
	<td width="100" align="right"><?php if (isset($error['first_name'])) { ?><span class="warning">**</span><?php } ?>First Name: </td>
	<td><input name="first_name" type="text" id="first_name" maxlength="50" <?php if(isset($error)) {echo "value='$first_name'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['last_name'])) { ?><span class="warning">**</span><?php } ?>Last Name: </td>
	<td><input name="last_name" type="text" id="last_name" maxlength="50" <?php if(isset($error)) {echo "value='$last_name'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['phone'])) { ?><span class="warning">**</span><?php } ?>
	<?php if (isset($error['email'])) { ?><span class="warning">**</span><?php } ?>Email:</td>
	<td><input name="email" type="text" id="email" maxlength="100" <?php if(isset($error)) {echo "value='$email'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['confirm'])) { ?><span class="warning">**</span><?php } ?>Confirm Email: </td>
	<td><input name="confirm" type="text" id="confirm" maxlength="100" <?php if(isset($error)) {echo "value='$confirm'";} ?> /></td>
  </tr>
  <tr>
    <td align="right"><?php if (isset($error['phone'])) { ?><span class="warning">**</span><?php } ?>Phone:</td>
    <td><input name="phone" type="text" id="phone" maxlength="20" <?php if(isset($error)) {echo "value='$phone'";} ?> /></td>
      </tr>
  <tr>
    <td align="right">Store:</td>
    <td><select name="store">
      <option value="Brookfield">Brookfield</option>
      <option value="Milwuakee">Milwaukee</option>
      <option value="Richfield" selected="selected">Richfield</option>
      </select>
    </td>
    </tr>
  <tr>
	<td width="100" align="right"> </td>
	<td><input type="Submit" name="ewReg" id="ewReg" value="Submit" /></td>
  </tr>
</table>
</form>
<?php } ?>
</div>


</body>
</html>

 

 

Here's the DB script that I have so far, it's not the greatest and isn't working completly, but it's what I have so far.  I'm having a lot of problems with the error handling.  Mail and Phone in the DB are Unique columns to limit duplicat entries.

 

<?php require_once('Connections/Registration.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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

// sest store location to dictate which table to post to
$storetable = $_POST['store'];

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "regForm")) {
  $insertSQL = sprintf("INSERT INTO {$storetable} (first_name, last_name, email, phone) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['phone'], "text"));

  mysql_select_db($database_Registration, $Registration);
  $Result1 = mysql_query($insertSQL, $Registration) or die("<h3>The email or phone that you entered is already registered.<br />You can only enter once for this drawing.<br />If you feel that this is an error, please use the back button<br />to make sure that you entered your information correctly.<br />If the problem persists, please contact the webmaster at bugs@digitaledgecc.com.</h3>");

  $insertGoTo = $_SERVER['PHP_SELF'];
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<link href="styles/basic.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="maincontent">

<?php if ($Result1) { ?>
<h1>Thank you for Registering</h1>
<p>You should recieve an email with your registration number and a special coupon just for you.  Please make sure that info@digitaledgecc.com is listed in your safelist so that your confirmation does not end up in junkmail.</p>
<?php } ?>


<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="regForm" id="regForm">
<table width="450" border="0" cellspacing="0" cellpadding="1" align="center">
  <tr>
	<td width="100" align="right"><?php if (isset($error['first_name'])) { ?><span class="warning">**</span><?php } ?>First Name: </td>
	<td><input name="first_name" type="text" id="first_name" maxlength="50" <?php if(isset($error)) {echo "value='$first_name'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['last_name'])) { ?><span class="warning">**</span><?php } ?>Last Name: </td>
	<td><input name="last_name" type="text" id="last_name" maxlength="50" <?php if(isset($error)) {echo "value='$last_name'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['phone'])) { ?><span class="warning">**</span><?php } ?>
	<?php if (isset($error['email'])) { ?><span class="warning">**</span><?php } ?>Email:</td>
	<td><input name="email" type="text" id="email" maxlength="100" <?php if(isset($error)) {echo "value='$email'";} ?> /></td>
  </tr>
  <tr>
	<td width="100" align="right"><?php if (isset($error['confirm'])) { ?><span class="warning">**</span><?php } ?>Confirm Email: </td>
	<td><input name="confirm" type="text" id="confirm" maxlength="100" <?php if(isset($error)) {echo "value='$confirm'";} ?> /></td>
  </tr>
  <tr>
    <td align="right"><?php if (isset($error['phone'])) { ?><span class="warning">**</span><?php } ?>Phone:</td>
    <td><input name="phone" type="text" id="phone" maxlength="20" <?php if(isset($error)) {echo "value='$phone'";} ?> /></td>
      </tr>
  <tr>
    <td align="right">Store:</td>
    <td><select name="store"<?php if(isset($error)) {echo "value='$store'";} ?>>
      <option value="Richfield">Richfield</option>
      <option value="Brookfield">Brookfield</option>
      <option value="Milwuakee">Milwaukee</option>
      </select>
    </td>
    </tr>
  <tr>
	<td width="100" align="right"> </td>
	<td><input type="Submit" name="ewReg" id="ewReg" value="Submit" /></td>
  </tr>
</table>
    <input type="hidden" name="MM_insert" value="regForm">
</form>

</div>

</body>
</html>

 

[attachment deleted by admin]

Link to comment
Share on other sites

and please, I'm really new to all this, so you won't hurt my feelings if you tell me that I'm going about this completely bassackwards and I need to start over.  My boss threw this project on my desk last Friday and I have to have the whole site redone by Monday. ::)

Link to comment
Share on other sites

does anyone have ANY ideas?

I hate to sound desparate, but I am.  I am rapidly running out of time and I still have the whole rest of the site to redesign.

 

Thanks in advance!

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.