Jump to content

PHP Form to email HELP


yogi101

Recommended Posts

Right, I use a php script to send the contents of a form to my email. It has been working fine until now I have started using .php extensions for my pages....

I have created a html page and saved it with a .php extension. This page has php includes in it i.e.

[code]<?php include("module_menu.php"); ?>[/code]

Also on this page is a form, this is sent to a script.

[code]<form method="POST" action="contact-script.php">[/code]

[code]<?php

## UNDERGROUND WEB SERVICES - CONTACT FORM ##

$email_to = "info@undergroundwebservices.co.uk";

$email_from = "info@undergroundwebservices.co.uk";

if($_POST['field_required']) {

$required = explode(",", $field_required);

}

$emailcontents = array();

while (list($key, $val) = @each($HTTP_POST_VARS)) {

$val = addslashes($val); $GLOBALS[$key] = $val;

if(!strstr($key,"field_")) {

if(count($required)) { if (in_array($key, $required) and !$val) { error("$key"); }}

array_push($emailcontents,"$key:\t$val");

}

}

if (!$_POST['$field_you_subject']) { $field_you_subject = "Underground Web Services - Contact Us Form"; }

if (!$_POST['$field_them_subject']) { $field_them_subject = "Underground Web Services - Thank You"; }

$emailcontents = implode("\n",$emailcontents);

$eheader= "to_you_header.txt";

$ehandle = fopen ($eheader, "r");

$head = fread ($ehandle, filesize ($eheader));

fclose ($ehandle);

$efooter= "to_you_footer.txt";

$ehandle = fopen ($efooter, "r");

$foot = fread ($ehandle, filesize ($efooter));

fclose ($ehandle);

$emailcontents = $head . "\n" . $emailcontents . "\n\n" . $foot;

if ($email and $name) {

mail("$email_to","$field_you_subject","$emailcontents","From: $name <$email>");

} elseif($email) {

mail("$email_to","$field_you_subject","$emailcontents","From: $email");

} else {

mail("$email_to","$field_you_subject","$emailcontents","From: $email_from");

}

$thanks= "thankyou.txt";

$thandle = fopen ($thanks, "r");

$thankyou = fread ($thandle, filesize ($thanks));

$thankyou = str_replace(XnameX, $name, $thankyou);

fclose ($thandle);

if($email and $field_no_thankyou != "1") {

mail("$email","$field_them_subject","$thankyou","From: $email_from");

}

$filename= "contact-confirm.php";

$handle = fopen ($filename, "r");

$contents = fread ($handle, filesize ($filename));

$contents = str_replace(XmessageX, $field_thankyou_message, $contents);

print $contents;

fclose ($handle);

function error($field) {

$filename= "contact-error.php";

$handle = fopen ($filename, "r");

$error = fread ($handle, filesize ($filename));

$error = str_replace(XfieldX, $field, $error);

print $error;

fclose ($handle);

exit();

}

?>[/code]


The script works and sends the user to the correct page depending on what they have entered i.e. all fields.. well it kind of works. Once the form is submitted the user should be sent to either contact-confirm.php or contact-error.php but it displays the php script URL in the browser address bar and and it does not show the php includes I have on contact-confirm.php & contact-error.php

I am new to php and I find this very wired, if the form is on a page with a .htm extension and once the user has submitted the form and is directed to other .htm files this script works fine.

Hope I have explainded enough for you to understand the problem. I can provide full sorce code and screenshots of the pages if that helps.

Can anyone help me resolve this please!!
Link to comment
Share on other sites

[!--quoteo(post=373045:date=May 10 2006, 01:51 PM:name=jfee1212)--][div class=\'quotetop\']QUOTE(jfee1212 @ May 10 2006, 01:51 PM) [snapback]373045[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm sure they are, but are the included files in the same directory? try using

[code]include("http://site.com/script.php");[/code]
[/quote]

yes everything apart from the images are in the same directory, will give the direct url ago now

Heres the source code of the page that contains the form, it is saved with a .php extension. The confirm and error pages which the script directs to once the form is submitted are exactly like this. I am sure the includes are conflicting.


[code]
<html>
<head>

<title>Underground Web Services</title>
<META name="description" content="Affordable web solutions company based in the UK."/>
<META name="keywords" content="web, design, development, company, service, services, bespoke, affordable, UK, cumbria, whitehaven, ashley graham, flash, graphic, graphics, domains, domain, ecommerce, host, hosting, webspace"/>
<META name="author" content="Web Design Company, Web (Creation) UK"/>
<META name="language" content="EN"/>
<META name="Classification" content="Web Design Company"/>
<META name="copyright" content="www.undergrounwebservices.co.uk"/>
<META name="robots" content="index, follow"/>
<META name="revisit-after" content="5 days"/>
<META name="reply-to" content="info@undergroundwebservices.co.uk"/>
<META name="document-classification" content="Web Design Development"/>
<META name="document-type" content="Public"/>
<META name="document-rating" content="Safe for Kids"/>
<META name="document-distribution" content="Global"/>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<META NAME="Title" CONTENT="Underground Web Services">
<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">


<link REL="stylesheet" TYPE="text/css" HREF="file:///C|/Documents%20and%20Settings/DJ%20YOGI/My%20Documents/WEBSITES%20&%20GRAPHICS/Websites/Underground%20Web%20Services/Web%20Design%20Webiste/Website%20(Newer)/styles.css">

<script language="JavaScript" type="text/JavaScript">
<!--

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>

<!-- Start of StatCounter Code -->
<script type="text/javascript" language="javascript">
var sc_project=1493051;
var sc_invisible=1;
var sc_partition=13;
var sc_security="703e5fa0";
var sc_remove_link=1;
</script>

<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><img  src="http://c14.statcounter.com/counter.php?sc_project=1493051&amp;java=0&amp;security=703e5fa0&amp;invisible=1" alt="how much traffic is going to my site" border="0"> </noscript>
<!-- End of StatCounter Code -->

</head>

<body>
<div align="center">
  <table width="200" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="6"><img src="images/template/top-l.jpg" width="6" height="6"></td>
      <td colspan="2"><img src="images/template/top-m.jpg" width="700" height="6"></td>
      <td width="6"><img src="images/template/top-r.jpg" width="6" height="6"></td>
    </tr>
    <tr>
      <td background="images/template/mid-l.jpg">&nbsp;</td>
      <td colspan="2" bgcolor="#000000"><?php include("module_menu.php"); ?></td>
      <td background="images/template/mid-r.jpg">&nbsp;</td>
    </tr>
    <tr>
      <td><img src="images/template/sli-l.jpg" width="6" height="6"></td>
      <td colspan="2"><img src="images/template/top-m.jpg" width="700" height="6"></td>
      <td><img src="images/template/sli-r.jpg" width="6" height="6"></td>
    </tr>
    <tr>
      <td background="images/template/mid-l.jpg">&nbsp;</td>
      <td colspan="2"><img src="images/head.jpg" width="700" height="95"></td>
      <td background="images/template/mid-r.jpg">&nbsp;</td>
    </tr>
    <tr>
      <td><img src="images/template/sli-l.jpg" width="6" height="6"></td>
      <td colspan="2"><img src="images/template/top-m.jpg" width="700" height="6"></td>
      <td><img src="images/template/sli-r.jpg" width="6" height="6"></td>
    </tr>
    <tr>
      <td background="images/template/mid-l.jpg">&nbsp;</td>
      <td width="491" bgcolor="#C8C8C8" class="modulemain" valign="top"><div align="center">
        <table width="482" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25" background="images/template/header.jpg" class="moduletitle header"><div align="left">• Contact Us •</div></td>
          </tr>
          <tr>
            <td bgcolor="#FFFFFF" class="modulecontent maintext textlinks" valign="top"><div align="left">
              <p>If you have any questions regarding our services  please feel free to contact us. A member of the team will be in contact within 24 hours.</p>
              <form method="POST" action="contact-script.php">
                  <input type="hidden" name="field_you_subject" value="A new web form submission">
                  <input type="hidden" name="field_them_subject" value="Thank you for your submission">
                  <input type="hidden" name="field_thankyou_message" value="">
                  <input type="hidden" name="field_required" value="Name,Email,Comments">
              <table width="411" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="70"><div align="left">Name:</div></td>
                  <td width="341"><input name="Name" type="text" id="Name"></td>
                  </tr>
                <tr>
                  <td><div align="left">Email:</div></td>
                  <td><input name="Email" type="text" id="Email" value="@"></td>
                  </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  </tr>
                <tr>
                  <td valign="top"><div align="left">Comments:</div></td>
                  <td><p>
                    <textarea name="Comments" cols="40" rows="4" id="Comments"></textarea>
                  </p>
                    <p>
                      <input name="Contact Us" type="Submit" id="Contact Us" value="Submit">
                      <input type="reset" name="Reset" value="Reset">
                    </p></td>
                  </tr>
              </table>
              </form>
                     </div>
              </td>
          </tr>
        </table>
      </div></td>
      <td width="209" bgcolor="#C8C8C8" class="modulesub" valign="top"><div align="center">
        <?php include("module_services.php"); ?>
      </div></td>
      <td background="images/template/mid-r.jpg">&nbsp;</td>
    </tr>
    <tr>
      <td><img src="images/template/sli-l.jpg" width="6" height="6"></td>
      <td colspan="2"><img src="images/template/top-m.jpg" width="700" height="6"></td>
      <td><img src="images/template/sli-r.jpg" width="6" height="6"></td>
    </tr>
    <tr>
      <td background="images/template/mid-l.jpg">&nbsp;</td>
      <td colspan="2" bgcolor="#000000" class="copyright"><div align="center">Copyright &copy; 2006 Underground Web Services. All rights reserved. </div></td>
      <td background="images/template/mid-r.jpg">&nbsp;</td>
    </tr>
    <tr>
      <td><img src="images/template/bot-l.jpg" width="6" height="6"></td>
      <td colspan="2"><img src="images/template/bot-m.jpg" width="700" height="6"></td>
      <td><img src="images/template/bot-r.jpg" width="6" height="6"></td>
    </tr>
  </table>
</div>
</body>
</html>
[/code]
Link to comment
Share on other sites

  • 2 weeks later...
When I change the links for the confirm & error page to .htm pages in the script i get this error message.

[code]Warning: filesize(): Stat failed for http://www.ibizamania.co.uk (errno=2 - No such file or directory) in /home/fhlinux205/u/undergroundwebservices.co.uk/user/htdocs/test/contact-script.php on line 64

Warning: fread(): Length parameter must be greater than 0. in /home/fhlinux205/u/undergroundwebservices.co.uk/user/htdocs/test/contact-script.php on line 64[/code]
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.