Avatar of Rob4077
Rob4077Flag for Australia asked on

How do I split this into a html file and a php file?

With the help of an EE Expert I obtained the attached code to create and send an email form. Is there any way I can split it into a HTML file and a separate PHP file?
# This code has been developed to collect data from an email form and email it to us

# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccTexth = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Email Form";
    $announce=" ";
else {
	if($fromText === "") die("No name!");
  	$title="Test Email Page";
  	$announce="Your Message has been Sent!";
  	$header = "From: ".$fromText."\r\n";
  	$header .= "Cc: ".$ccText."\n";
  	$header .= "Reply-To : ".$fromText."\r\n";
  	$header .= "Return-Path : ".$fromText."\r\n";
  	$header .= "X-Mailer: PHP\r\n";
  	$header .= "MIME-Version: 1.0\r\n";
  	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);

	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title><?php echo($title)?></title>
	<style type="text/css">
			A:link { color: #999999; }
			A:visited { color: #999999; }
			A:hover {color: #0099ff;}

	<script type="text/javascript">

		function check()
		var at=document.getElementById("fromText").value.indexOf("@");
		var eml=document.getElementById("fromText").value;
		var nam=document.getElementById("nameText").value;
		var alerttxt="";
		var submitOK="true";

		if (eml.length < 5 || at == -1)
			alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
			//return false;

		if (nam.length < 3)
			alerttxt=alerttxt+"Please enter your name.\r\n";
			//return false;

		if (submitOK=="false")
			return false;

		// -->

	<body bgcolor="#ddeedd">
		<div align="center">
			<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
					<td align="center">
						// if ($send != "") {
						//   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);
						//	 	}
						// ?>

						<p><b><font color="#000000" size="5">Test Email</font></b></p>
						<font size="4" color="#000000">
							<!--   <form method="POST" action="<?php echo($PHP_SELF)?>"> -->
							  <form method="POST" action="Email.php" onsubmit="return check();">
								<p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
								<p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
								<input type="hidden" name="subjectText" value="Web Mail">
								<p><font face="Arial" size="3"><b>Message Text:</b></font></p>
								<p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
								<p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
								<input type="hidden" name="state" value="1">
							  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Ok so I am better off leaving it all in a PHP file so I can get the desired response after submitting the form.

The reason I want to do it is because we have just had a bundle of books printed in readiness for this and the reference is to www.mywebsite.com/order so I was going to create a folder called order and put the form in there as order.htm. Is there any way I can achieve this with a PHP file?
Dave Baldwin

You can change the name of the file to 'order.php' if you want.  Just make sure and change it in the form tag too.

It is my understanding that     www.mywebsite.com/order             will open     index.htm     in the order folder.
If I rename it this fiel to      order.php     wouldn't I have to enter      www.mywebsite.com/order.php   to open it?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Dave Baldwin

Yes.  You might be able to make it 'index.php' in the 'http://www.mywebsite.com/order/' directory.

i'll try that to see if it works

Yep. It works. I just wasn't sure if it would find index.php.

Thanks very much for your help
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dave Baldwin

You're welcome, glad to help.

I have posted a new related question if you're interested in helping (hopefully the last one)