Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include page for email address 2

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi All,

This shouldn't be a real big issue for thos in the know. I'm managing a fairly large website that has a number of forms around it that send emails to certain people within the organisation as well as myself.

What I would like to do is have a separate page for all emails that I can include into the main php page that processes the form.

the line of code is pretty simple:
Code:
$emailTo = 'email@address.net.au';

I would like to have this line on a separate page so that if I need to change email addresses, I only need to change it once rather than going through every page that has my email address on it. What I can't seem to figure out is the correct syntax
I've tried:
a. include 'emailaddress.php';
b. $emailTo = + include 'emailaddress.php';
c. include ('emailaddress.php');

I did change the emailaddress.php page to suite the line of code. The files are in the same directory. The form appears to work ok, but I don't get any emails.
The emailaddress.php is:
Code:
<?
$emailTo = 'email@address.net.au'
?>
OR
Code:
<?
'email@address.net.au'
?>

Any help would be appreciated

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Hi

The a) and c) for the [tt]include[/tt] and the first code for emailaddress.php, and you will have the $emailTo variable available to display its value.

jedel said:
The form appears to work ok, but I don't get any emails.
What do you mean more exactly ? There are a lot of ways to deal with the task, we can not guess which one you implemented so which kind of problems you can have.

What should happen to that mail address anyway ? Is that page available on-line, so we could take a look at its intended functionality ?

Feherke.
 
Sure thing. the Form is at:
the php file that processes the form is at:

all that is supposed to happen is the php fiole validates the form entries and sends the results to the email address(es).

Once validated, it redirects to a success or error page. If it is successful the email is sent.

Re the quote you used. When I tested the php page with the "include" lines. The validation worked because I was redirected to the success page, but i did not get any emails.

Hope this helps a little

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Hi

Aha. So the value of $emailTo variable is necessary only for the mail notification. Correct. I was afraid you have some obscure client-side mail messing in mind.

Then we will need to see the code where you send the email. For now we do not know neither if you use the [tt]mail()[/tt] function or an external mailer class/function/script.

Feherke.
 
Ok. No Probs. He is a dump of the php page that processes the form...
Code:
<?PHP
######################################################
#                                                    #
#                Forms To Go 3.2.1                   #
#             [URL unfurl="true"]http://www.bebosoft.com/[/URL]               #
#                                                    #
######################################################



DEFINE('kOptional', true);
DEFINE('kMandatory', false);

DEFINE('kStringRangeFrom', 1);
DEFINE('kStringRangeTo', 2);
DEFINE('kStringRangeBetween', 3);
DEFINE('kYes', 'yes');
DEFINE('kNo', 'no');




error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

#----------
# Filter by Stop Words

function stopwords_check()
{

 $specialchars = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
 $escapedchars = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');

 $StopWordsFile = 'badwords.txt';

 if (file_exists($StopWordsFile) === false) {
  echo '<html><head><title>Error</title></head><body>The Stop Words file: <b>' . $StopWordsFile . '</b> cannot be found on the server.</body></html>';
  exit;
 }
 
 $bannedstopwords = file($StopWordsFile);

 foreach ($_POST as $fieldname => $fieldvalue) {
  foreach ($bannedstopwords as $stopword_key => $stopword_value) {
   $stopword_value = str_replace($specialchars, $escapedchars, $stopword_value);
   $pattern = '/.*' . rtrim($stopword_value) . '.*/i';
   if (is_array($fieldvalue)) {
    $fieldvalue = implode(",", $fieldvalue);
   }
   if (get_magic_quotes_gpc()) {
    $fieldvalue = stripslashes($fieldvalue);
   }
   if (preg_match($pattern, $fieldvalue)) {
    header('Location: [URL unfurl="true"]http://www.calvaryaog.org.au/church/general/Banned.asp');[/URL]
    exit;
   }
  }
 } 
}

#----------
# Filter by IP Address

function ipaddress_check($ClientIP)
{

 $BannedIPsFile = 'IPAddresses.txt';

 if (file_exists($BannedIPsFile) === false) {
  echo '<html><head><title>Error</title></head><body>The banned IPs file: <b>' . $BannedIPsFile . '</b> cannot be found on the server.</body></html>';
  exit;
 }
 
 $bannedips = file($BannedIPsFile);
 
 foreach ($bannedips as $ip_key => $ip_value) {
  if (rtrim($ip_value) == $ClientIP) {
   header('Location: [URL unfurl="true"]http://www.calvaryaog.org.au/church/general/Banned.asp');[/URL]
   exit;
  }
 } 
}

function DoStripSlashes($FieldValue) 
{ 
 if ( get_magic_quotes_gpc() ) { 
  if (is_array($FieldValue) ) { 
   return array_map('DoStripSlashes', $FieldValue); 
  } else { 
   return stripslashes($FieldValue); 
  } 
 } else { 
  return $FieldValue; 
 } 
}

#----------
# FilterCChars:

function FilterCChars($TheString)
{
 return preg_replace('/[\x00-\x1F]/', '', $TheString);
}

#----------
# Validate: String

function check_string($value, $low, $high, $mode, $limitalpha, $limitnumbers, $limitemptyspaces, $limitextrachars, $optional)
{
 if ($limitalpha == kYes) {
  $regexp = 'A-Za-z';
 }
 
 if ($limitnumbers == kYes) {
  $regexp .= '0-9'; 
 }
 
 if ($limitemptyspaces == kYes) {
  $regexp .= ' '; 
 }

 if (strlen($limitextrachars) > 0) {
 
  $search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
  $replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');

  $regexp .= str_replace($search, $replace, $limitextrachars);

 }

 if ( (strlen($regexp) > 0) && (strlen($value) > 0) ){
  if (preg_match('/[^' . $regexp . ']/', $value)) {
   return false;
  }
 }

 if ( (strlen($value) == 0) && ($optional === kOptional) ) {
  return true;
 } elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
  return true;
 } elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
  return true;
 } elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
  return true;
 } else {
  return false;
 }

}



if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
 $ClientIP = $_SERVER['REMOTE_ADDR'];
}

stopwords_check();
ipaddress_check($ClientIP);
$FTGtitle = DoStripSlashes( $_REQUEST['title'] );
$FTGcategory = DoStripSlashes( $_REQUEST['category'] );
$FTGURL = DoStripSlashes( $_REQUEST['URL'] );
$FTGdescription = DoStripSlashes( $_REQUEST['description'] );
$FTGSubmit2 = DoStripSlashes( $_REQUEST['Submit2'] );
$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );


# Fields Validations

$ValidationFailed = false;

if (!check_string($FTGtitle, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
 $ValidationFailed = true;
 $FTGtitle_errmsg = 'Please enter a title';
 $ErrorList .= $FTGtitle_errmsg . '<br/>';
}
if (!check_string($FTGURL, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
 $ValidationFailed = true;
 $FTGURL_errmsg = 'Please enter the website address';
 $ErrorList .= $FTGURL_errmsg . '<br/>';
}


# Embed error page and dump it to the browser

if ($ValidationFailed === true) {

 $FileErrorPage = 'error.html';

 if (file_exists($FileErrorPage) === false) {
  echo '<html><head><title>Error</title></head><body>The error page: <b>' . $FileErrorPage. '</b> cannot be found on the server.</body></html>';
  exit;
 }

 $FileHandle = fopen ($FileErrorPage, "r");
 $ErrorPage = fread ($FileHandle, filesize($FileErrorPage));
 fclose ($FileHandle);

 $ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage);

 $ErrorPage = str_replace('<!--FIELDVALUE:title-->', $FTGtitle, $ErrorPage);
 $ErrorPage = str_replace('<!--FIELDVALUE:category-->', $FTGcategory, $ErrorPage);
 $ErrorPage = str_replace('<!--FIELDVALUE:URL-->', $FTGURL, $ErrorPage);
 $ErrorPage = str_replace('<!--FIELDVALUE:description-->', $FTGdescription, $ErrorPage);
 $ErrorPage = str_replace('<!--FIELDVALUE:Submit2-->', $FTGSubmit2, $ErrorPage);
 $ErrorPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $ErrorPage);
 $ErrorPage = str_replace('<!--ERRORMSG:title-->', $FTGtitle_errmsg, $ErrorPage);
 $ErrorPage = str_replace('<!--ERRORMSG:URL-->', $FTGURL_errmsg, $ErrorPage);
  

 echo $ErrorPage;
 exit;

}
# Email to Form Owner

$emailSubject = FilterCChars("BIBLE COLLEGE WEBSITE LINK");

$emailBody = chunk_split(base64_encode("<html>\n"
 . "<head>\n"
 . "<title>Web page error</title>\n"
 . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n"
 . "<link href=\"[URL unfurl="true"]http://www.calvaryaog.org.au/css/CSS_Styles.css\"[/URL] rel=\"stylesheet\" type=\"text/css\">\n"
 . "</head>\n"
 . "\n"
 . "<body>\n"
 . "<table width=\"500\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n"
 . "  <tr> \n"
 . "    <td colspan=\"2\"><img src=\"[URL unfurl="true"]http://www.calvaryaog.org.au/bible_college/images/ModuleLogo.png\"[/URL] width=\"552\" height=\"134\"></td>\n"
 . "  </tr>\n"
 . "  <tr> \n"
 . "    <td colspan=\"2\" class=\"normalTxt\">Some one has suggested a website link for the bible college. Details below. </td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td width=\"137\" align=\"right\" valign=\"top\" class=\"normalTxtnobox\"><strong>Title: </strong></td>\n"
 . "    <td width=\"463\" valign=\"top\" class=\"normalTxtnobox\">$FTGtitle </td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>Category</strong></td>\n"
 . "    <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGcategory</td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>URL</strong></td>\n"
 . "    <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGURL </td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>Description: </strong></td>\n"
 . "    <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGdescription </td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td colspan=\"2\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><hr size=\"1\"></td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td align=\"right\" valign=\"top\" class=\"normalTxtnobox\">IP Address: </td>\n"
 . "    <td valign=\"top\" class=\"normalTxtnobox\">$ClientIP </td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td align=\"right\" valign=\"top\" class=\"normalTxtnobox\">Date Sent: </td>\n"
 . "    <td valign=\"top\" class=\"normalTxtnobox\">" . date('d/m/y') . " </td>\n"
 . "  </tr>\n"
 . "</table>\n"
 . "</body>\n"
 . "</html>\n"
 . ""))
 . "\n";
 //$emailTo = + include ('emailaddress.php');
 $emailTo = 'email@address.net.au';
  
 $emailFrom = FilterCChars("weblink@biblecollege.com.au");
  
 $emailHeader = "From: $emailFrom\n"
  . "MIME-Version: 1.0\n"
  . "Content-Type: text/html; charset=\"ISO-8859-1\"\n"
  . "Content-Transfer-Encoding: base64\n"
  . "\n";
  
 mail($emailTo, $emailSubject, $emailBody, $emailHeader);


# Embed success page and dump it to the browser

$FileSuccessPage = 'success.html';

if (file_exists($FileSuccessPage) === false) {
 echo '<html><head><title>Error</title></head><body>The success page: <b> ' . $FileSuccessPage . '</b> cannot be found on the server.</body></html>';
 exit;
}

$FileHandle = fopen ($FileSuccessPage, "r");
$SuccessPage = fread ($FileHandle, filesize($FileSuccessPage));
fclose ($FileHandle);

$SuccessPage = str_replace('<!--FIELDVALUE:title-->', $FTGtitle, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:category-->', $FTGcategory, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:URL-->', $FTGURL, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:description-->', $FTGdescription, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:Submit2-->', $FTGSubmit2, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $SuccessPage);


echo $SuccessPage;
exit;
?>
I have the $emailTo line set at the original. The line above is my attempt at an include.
Thanks for looking at this

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
2 things...

While testing, make sure to print the variable being called from the include. This makes testing quicker since you do not have to run to your mail program to find the message.

Maybe is was just accidental when you posted your sample code, but you should make sure your script has a semicolon at the end of the variable definition.
 
Hi

That is the b) variant from your original question. As I wrote, a) and c) are correct. This must work if the two PHP files are in the same directory :
Code:
[highlight #eee] 265 [/highlight] . "</html>\n"
[highlight #eee] 266 [/highlight] . ""))
[highlight #eee] 267 [/highlight] . "\n";
[highlight #eee] 268 [/highlight] [red]include 'emailaddress.php';[/red]
[highlight #eee] 269 [/highlight]
[highlight #eee] 270 [/highlight]
[highlight #eee] 271 [/highlight] $emailFrom = FilterCChars("weblink@biblecollege.com.au");
Code:
<?php
$emailTo = 'email@address.net.au';
?>

Feherke.
 
Thanks Guys,

All is well in the php world now. Have a star each!!

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top