Jump to content

Interesting Dilema; PHPMail() Not working with includes..


monkeypaw201

Recommended Posts

Hey guys;

 

I have a page with a form(form.php) that posts to another page (index.php?page=sent) the second page includes the script used to send the email. It works such that it sends the emails but it seems that the posted variables got lost somewhere... am i missing something?

 

Thanks

Check your names for the form and input fields and make sure that they match the names that you are using to access the data in the php script. Try print_r($_POST); to display all of the data.

 

If you still can't get it, post the relevent parts of form.php and index.php

 

 

Check your names for the form and input fields and make sure that they match the names that you are using to access the data in the php script. Try print_r($_POST); to display all of the data.

 

If you still can't get it, post the relevent parts of form.php and index.php

 

 

 

it outputs

Array ( )

 

the form.php code is

<form name="form1" method="post" action="http://www.domain.com/Dev/home.php?page=contact_send">
  <table width="100%" border="0">
    <tr>
      <td>Full Name:</td>
      <td><span id="sprytextfield1">
        <label>
        <input type="text" name="full_name" id="full_name">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your Full Name!</span></span></td>
    </tr>
    <tr>
      <td>E-Mail Address:</td>
      <td><span id="sprytextfield2">
        <label>
        <input type="text" name="email" id="email">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your E-Mail Address!</span></span></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><span id="sprytextarea1">
        <label>
        <textarea name="message" id="message" cols="45" rows="5"></textarea>
        </label>
      <span class="textareaRequiredMsg">You Must Enter A Message To Send!</span></span></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <div align="center">
          <input type="submit" name="button" id="button" value="Send Message">
        </div>
      </label></td>
    </tr>
  </table>
</form>

 

the send.php code is;

<?php
$EmailFrom = "noreply@" . substr($row_Settings['base_url'],0,11);
$EmailTo = "[email protected]";

//The subject can be overriden by simply replacing it below
$Subject = "";
$FullName = Trim(stripslashes($_POST['full_name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Message = Trim(stripslashes($_POST['message'])); 
$Body = "Hello; \n\n You have recieved an email from ";
$Body .= "you website's contact form. The message is below for your convenience. \n\n ****************************** \nFull Name: ";
$Body .= $_POST['full_name'];
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n ****************************** \n\n This Is An Automatically Generated Message, Do Not Repond!";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
  echo "<center><em>Thank You " . $_POST['full_name'] . " , Your Message Has Been Sent!</em></center>";
}
else{
  echo "<center><em>There Was An Error Sending The Message, Please Try Again!</em></center>";
}
?>

 

It seems to not want to post across...

Are you posting accross domains? Using the full URL in the action attribute of the form made me think that. I don't know if all browsers would like that. But that is just a guess. But I really don't have a clue if thats ok or not. Just an idea

 

Where did you put the print_r($_POST);? Which file? Which line?

I printed in the send.php right below the <?php tag.

 

Its all on the same domain, everything is just so sunk into directories, i choose to use the domain for ease..you made me think about that too, so im going to try and remove the domain and just run it with a lot of ../'s :P

 

I'll post what happens

I noticed that your action URL ends with 'home.php?page=contact_send' ( unless you are using mod_rewrite ) that means that the request is getting routed through 'home.php' before it finally gets to 'send.php' Double check that nothing else between home.php and send.php is overwriting the $_POST variable.

Sadly enought, even running it with this code

<form name="form1" method="post" action="home.php?page=contact_send">
  <table width="100%" border="0">
    <tr>
      <td>Full Name:</td>
      <td><span id="sprytextfield1">
        <label>
        <input type="text" name="full_name" id="full_name">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your Full Name!</span></span></td>
    </tr>
    <tr>
      <td>E-Mail Address:</td>
      <td><span id="sprytextfield2">
        <label>
        <input type="text" name="email" id="email">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your E-Mail Address!</span></span></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><span id="sprytextarea1">
        <label>
        <textarea name="message" id="message" cols="45" rows="5"></textarea>
        </label>
      <span class="textareaRequiredMsg">You Must Enter A Message To Send!</span></span></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <div align="center">
          <input type="submit" name="button" id="button" value="Send Message">
        </div>
      </label></td>
    </tr>
  </table>
</form>

 

doesn't change anything...  I also tried using the $_GET function just for curiosity sake..and.. i got a blank page instead of a n either success or error as in the send.php code ...

 

I'm sort of pulling my hair out, so if anyone has any suggestions, post them please

 

Thanks

 

Add-On ::

I noticed that your action URL ends with 'home.php?page=contact_send' ( unless you are using mod_rewrite ) that means that the request is getting routed through 'home.php' before it finally gets to 'send.php' Double check that nothing else between home.php and send.php is overwriting the $_POST variable.

 

I am not using mod_rewrite, but both scripts are getting includes on the home.php script, could that be a factor?

Just for curiosity, try posting the form directly to 'send.php' to see if you get anything.

 

It ran perfectly.. so something is disrupting the code on home.php or one of its countless included scripts... to make things all the more confusing, there are no forms or anything that would interfere with a $_POST (that i can see/think of)

Well I guess you know where to look now. If you have a good devlopment environment ( AKA linux :-) ), you can just run a search for '$_POST' or '$HTTP_POST_VARS ' through all of those include files that are included before yours and see if anybody was messing with them.

 

i ran through them all and even removed the unnecessary files to run the contact form and still received the same results... is there any other way to post the variables without using GET? i don't want users to be able to mess with the code...

1 more thing i tried

 

I attached the print_r($_POST) to home.php at the bottom and found out something interesting...

 

it displayed:

at the bottom... its gets passed but its not going into the form...

 

whats going on?!?!

try this as one page please...

 

just enter your email address m8....

 

<?php


if ($_POST['submit']){

if($_GET['page']=="contact_send"){

	$FullName = Trim(stripslashes($_POST['full_name'])); 
        $Email = Trim(stripslashes($_POST['email'])); 
        $Message = Trim(stripslashes($_POST['message'])); 

$to = '[email protected]';

$subject = 'Testing mail!';


$mes = "Hello; \n\n You have recieved an email from ";
$mes .= "you website's contact form. The message is below for your convenience. \n\n ****************************** \nFull Name: ";
$mes .= $full_name;
$mes .= "\n";
$mes .= "Email: ";
$mes .= $Email;
$mes .= "\n";
$mes .= "Message: ";
$mes .= $Message;
$mes .= "\n ****************************** \n\n This Is An Automatically Generated Message, Do Not Repond!";

$message = $mes;

$headers = "From: [email protected]\r\n" .
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
if(mail($to, $subject, $message, $headers)){

echo "<center><em>Thank You " . $_POST['full_name'] . " , Your Message Has Been Sent!</em></center>";

}else{
  
echo "<center><em>There Was An Error Sending The Message, Please Try Again!</em></center>";
}
  }
   }
?>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>?page=contact_send">

<table width="100%" border="0">
    <tr>
      <td>Full Name:</td>
      <td><span id="sprytextfield1">
        <label>
        <input type="text" name="full_name" id="full_name">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your Full Name!</span></span></td>
    </tr>
    <tr>
      <td>E-Mail Address:</td>
      <td><span id="sprytextfield2">
        <label>
        <input type="text" name="email" id="email">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your E-Mail Address!</span></span></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><span id="sprytextarea1">
        <label>
        <textarea name="message" id="message" cols="45" rows="5"></textarea>
        </label>
      <span class="textareaRequiredMsg">You Must Enter A Message To Send!</span></span></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <div align="center">
          <input type="submit" name="submit" id="button" value="Send Message">
        </div>
      </label></td>
    </tr>
  </table>
</form>


ok, so home.php code:

 

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

mysql_select_db($database_ManageYourVA, $ManageYourVA);
$query_Settings = "SELECT * FROM settings WHERE id = 12";
$Settings = mysql_query($query_Settings, $ManageYourVA) or die(mysql_error());
$row_Settings = mysql_fetch_assoc($Settings);
$totalRows_Settings = mysql_num_rows($Settings);

mysql_select_db($database_ManageYourVA, $ManageYourVA);
$query_menu = "SELECT * FROM menu WHERE active = 'Yes'";
$menu = mysql_query($query_menu, $ManageYourVA) or die(mysql_error());
$row_menu = mysql_fetch_assoc($menu);
$totalRows_menu = mysql_num_rows($menu);

mysql_select_db($database_ManageYourVA, $ManageYourVA);
$query_Page = "SELECT * FROM page WHERE active = 'Yes' AND url_title = '$_GET

'";
$Page = mysql_query($query_Page, $ManageYourVA) or die(mysql_error());
$row_Page = mysql_fetch_assoc($Page);
$totalRows_Page = mysql_num_rows($Page);
?>
<?php
include_once("Themes/" . $row_Settings['theme_directory'] . "theme.php");

?>
<?php
mysql_free_result($Settings);

mysql_free_result($menu);

mysql_free_result($Page);
?>

 

the theme.php code:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $row_Settings['airline_name']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="<?php echo $row_Settings['base_url'] . $row_Settings['directory'] . "Themes" . $row_Settings['theme_directory']; ?>Style/style.css" />
<?php include_once($row_Settings['base_url'] . $row_Settings['directory'] . "Includes/overview.php"); ?>

</head>
<body class="hasOneColumn noSidebar">

<div id="fw-container">
<div id="fw-head">

   <h1 id="fw-title"><a href="<?php echo $row_Settings['base_url'] . $row_Settings['directory']; ?>home.php"><?php echo $row_Settings['airline_name']; ?></a></h1>
   <h2 id="fw-smalltitle"></h2>
   <div id="logo-div" class="fw-logo"></div>
</div>


<div id="fw-blockContainer">
   <div id="fw-mainnavwrap">
     <div id="fw-nav-menu">
       <ul>
<?php
if(!$row_menu['location'] == "top"){}else{

mysql_select_db($database_ManageYourVA, $ManageYourVA);
$query_menu_items = "SELECT * FROM menu_links WHERE location = 'top' AND active = 'Yes' ORDER BY `order` ASC";
$menu_items = mysql_query($query_menu_items, $ManageYourVA) or die(mysql_error());
$row_menu_items = mysql_fetch_assoc($menu_items);
$totalRows_menu_items = mysql_num_rows($menu_items);

do { ?>
<li><A class="section" href="home.php?page=<?php echo $row_menu_items['link']; ?>"><?php echo $row_menu_items['name']; ?></A></li>
<?php } while ($row_menu_items = mysql_fetch_assoc($menu_items));

}
?>
       </ul>

     </div>
   </div>

<div id="fw-bigcontain">
  

  <div id="fw-columnContainer">
    <div id="fw-leftColumn">
      
    </div>
  
    <div id="fw-mainColumn">
      <div class="fw-paragraph">

  <div class="fw-paragraphtop"></div>
  <h3 class="fw-title"><?php echo $row_Page['title']; ?></h3>
  <div class="fw-text">
    <p><?php 
if($row_Page['custom'] == "Yes")
{ 
include_once($row_Settings['base_url'] . $row_Settings['directory'] . "Pages/Custom/" . $row_Page['custom_link']); 
} 
elseif($row_Page['custom'] == 'AO')
{ 
include_once($row_Settings['base_url'] . $row_Settings['directory'] . "Pages/Add_Ons/" . $row_Page['custom_link']); 
} 
else
{ 
echo $row_Page['content']; 
} 
?></p></div>

  <div class="fw-paragraphbottom"></div>
  </div>
    </div>  
    
    <div id="fw-rightColumn">
        
    </div>
  </div>
</div>

<div id="fw-sidebar">
   <div id="fw-sidebarbegin"></div>
     {ParagraphsSidebar}  
   <div id="fw-sidebarend"></div>

</div>
   <div class="clears">
</div>
</div>

<div id="fw-footer">
   <p class="fw-footertext"><?php echo $row_Settings['copyright']; ?></p>
<span class="powered_by">Powered By My Script</span> 
</div>
</div>

</body>
</html>

 

the form and the send code in the first or second posts...

 

Any help would be appreciated.. im lost on what the problem is..

Archived

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

×
×
  • 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.