Hi
A newbie question using php.
I have a form which is generated from a database system.
It is a form to reply to an email.
The database system also creates a text file which has in it the body of the email. It finds the mime part and creates a separate file.
This form then reads the text file and puts the contents into the body field on the form.
Unfortunately the message gets posted at the top of the form and not in the body field.
Could someone point out where I am going wrong.
Thanks for helping me.
A newbie question using php.
I have a form which is generated from a database system.
It is a form to reply to an email.
The database system also creates a text file which has in it the body of the email. It finds the mime part and creates a separate file.
This form then reads the text file and puts the contents into the body field on the form.
Unfortunately the message gets posted at the top of the form and not in the body field.
Could someone point out where I am going wrong.
Thanks for helping me.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Email Editor</title>
<link rel=stylesheet href="styles.css">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="edithtml.js"></SCRIPT>
<script language="JavaScript">
function loadIframe(){ iView1.document.body.innerHTML=document.forms['email'].dbhtml.value; }
function processFocus(){
var htmlCode= iView1.document.body.innerHTML;
document.email.html.value = htmlCode;
document.forms['email'].action.value="submit";
document.forms['email'].submit();
}
</script>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<?php
require("class.phpmailer.php");
$from="nobody@nowhere.co.uk";
$to="admin@accounts.com";
$cc="";
$bcc="";
$subject="RE: Email";
$myFile = "test.txt";
$fh = fopen($myFile, 'r');
$body = fread($fh, filesize($myFile));
fclose($fh);
If (isset($_POST['action'])) {
$filename = 'body.TXT';
If (!$handle = fopen($filename, 'a')){
echo "Cannot open file($filename)";
exit;
}
If (fwrite($handle,$_POST['html']) === False){
echo "Cannot write to file($filename)";
exit;
}
echo "Success, wrote to file (<a href='" . $filename . "'>" . $filename . "</a><br/>)";
fclose($handle);
$Sender="nobody@nowhere.co.uk";
$mail=new PHPMailer(True);
$mail->IsSMTP();
try{
$mail->SMTPDebug=1;
$mail->SMTPAuth=True;
$mail->SMTPSecure="ssl";
$mail->Host="smtp.gmail.com";
$mail->Port=465;
$mail->Username="account@gmail.com";
$mail->Password="12345";
$mail->AddAddress($_POST['to'], 'Name Surname ');
$mail->SetFrom('nobody@nowhere.co.uk', 'Sender');
$mail->AddReplyTo('nobody@nowhere.co.uk', 'Sender');
$mail->From = "'nobody@nowhere.co.uk";
$mail->Subject = $_POST['subject'];
$mail->MsgHTML(file_get_contents("body.TXT"));
$mail->Send();
echo"Message Sent OK</p>
";
}catch(phpmailerException$e){
echo$e->errorMessage();
}catch(Exception$e){
echo$e->getMessage();
}
} Else {
echo "<p class=\"h1\">Email Form</h1>";
?>
<form action="Script11-01-201016-39-4412194.PHP" method="POST" name="email">
<table width='100%' border='0' align='center' style='width: 100%;'>
<tr><td width="10%"><p class="body">To:</p></td><td width="90%"><input type='to' name='to' size='100' value='<?php echo $to;?>'></td></tr>
<tr><td><p class="body">Cc:</p></td><td><input type='text' name='cc' size='100' value='<?php echo $cc;?>'></td></tr>
<tr><td><p class="body">Bcc:</p></td><td><input type='text' name='bcc' size='100' value='<?php echo $bcc;?>'></td></tr>
<tr><td><p class="body">Subject:</p></td><td><input type='text' name='subject' size='100' value='<?php echo $subject;?>'></td></tr>
<input type="hidden" name="action" value=" ">
<input type="hidden" name="dbhtml" value="<?php echo $body;?>">
<body bgcolor="#FFFFFF" onLoad="loadIframe()"><Center ><br>
<table width="800" border="1" align="left" cellpadding="0" cellspacing="0" bordercolor="0">
<tr>
<td width="50%"><table id="tblCtrls1"width="800"height="30px"border="0"borderColor=""cellspacing="0"cellpadding="0"></td></tr>
<tr><td class="tdClass"bgcolor=#D6D3CE><img id="boldBut1" alt="Bold " class="butClass" src="buttons/bold.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBold1()">
<img id="italBut1" alt="Italic " class="butClass" src="buttons/italic.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doItalic1()">
<img id="undeBut1" alt="Underline " class="butClass" src="buttons/underline.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doUnderline1()">
<img id="leftBut1" alt="Left" class="butClass" src="buttons/left.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doLeft1()">
<img id="centBut1" alt="Center " class="butClass" src="buttons/center.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doCenter1()">
<img id="rightBut1" alt="Right" class="butClass" src="buttons/right.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doRight1()">
<img id="ordBut1" alt="Ordered List" class="butClass" src="buttons/ordlist.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doOrdList1()">
<img id="unordBut1" alt="Bulleted List" class="butClass" src="buttons/bullist.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBulList1()">
<img id="fcolBut1" alt="Text Color" class="butClass" src="buttons/forecol.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doForeCol1()">
<img id="bcolBut1" alt="Background color " class="butClass" src="buttons/bgcol.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBackCol1()">
<img id="linkBut1" alt="Hyperlink" class="butClass" src="buttons/link.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doLink1()">
<img id="ruleBut1" alt="Horizontal Rule" class="butClass" src="buttons/rule.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doRule1()">
<img id="cutBut1" alt="Cut" class="butClass" src="buttons/cut.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doCut1()">
<img id="copyBut1" alt="Copy" class="butClass" src="buttons/copy.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doCopy1()">
<img id="pasteBut1" alt="Paste" class="butClass" src="buttons/paste.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doPaste1()">
<img id="undoBut1" alt="Undo" class="butClass" src="buttons/undo.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doUndo1()">
<img id="printBut1" alt="Print" class="butClass" src="buttons/print.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="javascript:window.print()">
<img id="saveBut1" alt"Save" class="butClass" src="buttons/save.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="processFocus()">
</td>
</tr>
</Table>
<iframe onBlur="doValueUpdate1()" id="iView1" style="width: 800;height:400;background:#f9f5ca;"></iframe>
<input type="hidden" name="__data1" value=""><input type="hidden" name="__control_1" value=""><input type="hidden" name="html" value="">
<table width="800" height="30px" border="0" cellspacing="0" cellpadding="0" bgcolor="#D6D3CE">
<tr><td class=tdClass>Ê  ;
<select id="selSize1" onChange="doSize1(this.options[this.selectedIndex].value); this.selectedIndex=0;" class=dropDown>
<option value="">-- Size --</option>
<option value="1">Smallest</option>
<option value="2">+1</option>
<option value="3">+2</option>
<option value="4">+3</option>
<option value="5">+4</option>
<option value="6">+5</option>
<option value="7">+6</option>
</select><select id="selHeading1"onChange="doHead1(this.options[this.selectedIndex].value);this.selectedIndex=0;" class=dropDown>
<option value="">-- Heading --</option>
<option value="Heading 1">H1</option>
<option value="Heading 2">H2</option>
<option value="Heading 3">H3</option>
<option value="Heading 4">H4</option>
<option value="Heading 5">H5</option>
<option value="Heading 6">H6</option>
</select> </td>
</tr>
</Table></td>
</tr>
</Table>
</td></tr></Table>
<script language="JavaScript">
var viewMode1 = 1;
Init1();
</script><br>
</form>
<?php }?>
</Table>
</body>
</html>