Click to See Complete Forum and Search --> : PHP Form Autoresponder


nkokhi
05-07-2008, 07:58 AM
HI

Im having some problems with PHP autoresponder functions.

1. I need to set the “From” header that will appear on Sender’s “From: header”
2. I need to attached / include the sent message with the confirmation.

PHP is new to my world and I need some help. The current script is working but the Autoresponder message header shows: me@www6.cpt341.host-h.net and I need to change this to ie. Me@mydomain.com

With the inclusion of sent message; Im totally blank.

Herewith the form code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Contact us</title>

<style type="text/css">
<!--
td.form { color: #606060; font-family: "Arial", "Helvetica", "sans-serif"; font-size: 12; }
td.main { color: #000000; font-family: "Arial", "Helvetica", "sans-serif"; font-size: 12; }
font.form_check { color: red; }
input { font-family: "Arial", "Helvetica", "sans-serif"; color:#606060; font-size: 12px; }
textarea { font-family: "Arial", "Helvetica", "sans-serif"; color:#606060; font-size: 12px; }

.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 11;
}
-->
</style>

</head>
<body>


<!-- Put headers above here -->
<span class="style1">
<?php
/*

*/
//Here are the things you need to change
//Your email address
$emaddress = "me@me.co.za";
//This is the colour that will go round the box if the user forgets to fill it in in HEX
$embordercolor = "#ff0000";
//The title of your website
$sitetitle = "me";
//HTML E-mail. If you can recieve HTML e-mail you should set this to 1
//0 is off and 1 is on. Defult is off. You may want to change the $autobody variable in the code
$htmlemail = 1;
//Auto-responder. This will send a thank you message to the user. Note : Some people may find this annoying
//0 is off and 1 is on. Defult is off. You may want to change the $autobody variable in the code
$autoresponder = 1;
//Do not change anything below here
/*----------------------------------------------------------------------------------*/
$validstring = '^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3}))$';
if (!eregi($validstring,$email)&&$email) {
$emailcorrect = 0;
}
else {
$emailcorrect = 1;
}
if($email&&$message&&$subject&&$name&&$emailcorrect) {
if($autoresponder)
{
$autobody = "Thank You, $name for sending me an e-mail through my website.

From
$sitetitle
";
$autosubject = "Thank you from $sitetitle";
mail($email, $autosubject, $autobody, "From: $sitetitle");
}
$headers = "From: " . trim($name) . "\n";
if($htmlemail)
{

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$body = "E-mail is from " . $name . " at " . $email .

".<br><br>This is the message sent:<br><br>" . "Subject: - " . $subject ."<br><br>"


. $message . ".";

}
else
{

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$body = "E-mail is from " . $name . " at " . $email." - Company name: " .$company ." - Membership number: " . $Membership_no



."<br><br>". "Subject: - " . $subject ."<br><br>"

. $message . ".";

}
else
{

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$body = "E-mail is from $name at $email

Company name: $company

Membership number: $Membership_no.

Subject: $subject
$Message \n-----------------------------------------------------------------------\n $message \n-----------------------------------------------------------------------\n";



}
$thesubject = "MEMBERSHIP Website Equiry: $subject";
if(mail($emaddress, $thesubject, $body, $headers)) {
echo "<br><br>Your e-mail was sent successfully. Thank you for the message " . $name . ".";
}
else {
echo "Sorry, $name, your e-mail was not sent successfully please try again<br><br>";
echo "<form name=\"theform\" method=\"get\" action=\"contact_fundi.php\">";

echo "Your name:<br><input name=\"name\" type=\"text\" value=\"$name\"><br>";
echo "Your e-mail:<br><input name=\"email\" type=\"text\" value=\"$email\"><br>";
echo "Your company:<br><input name=\"company\" type=\"text\" value=\"$company\"><br>";
echo "Membership no.:<br><input name=\"Membership_no\" type=\"text\" value=\"$Membership_no\"><br>";

echo "Subject:<br><input name=\"subject\" type=\"text\" value=\"$subject\"><br>";

echo "Message:<br><textarea name=\"message\" rows=4 cols=30>$message</textarea>";
echo "<br><input type=\"submit\" value=\"Send\" class=\"submit\"></form>";

}




}
if ((!$emailcorrect||!$email||!$message||!$subject||!$name)&&!(!$email&&!$message&&!$subject&&!$name)) {
echo "The Following errors have occurred.<br>";
echo "<ul>";
if (!$emailcorrect) {
echo "<li> Your e-mail address is not valid.";
}
if (!$email||!$message||!$subject||!$name) {
echo "<li> You have forgotten to fill in a detail.";
}
echo "</ul>Please correct the error(s) and resubmit the form";

echo "<style>";
if (!$email||!$emailcorrect) {
echo ".email {border-color:" . $embordercolor . ";}";
}
if (!$name) {
echo ".name {border-color:" . $embordercolor . ";}";
}
if (!$message) {
echo ".message {border-color:" . $embordercolor . ";}";
}
if (!$subject) {
echo ".subject {border-color:" . $embordercolor . ";}";
}
echo "</style>";
echo "<form name=\"theform\" method=\"get\" action=\"contact_fundi.php\">";

echo "Your name:<br><input name=\"name\" type=\"text\" value=\"$name\" class=\"name\"><br>";
echo "Your e-mail:<br><input name=\"email\" type=\"text\" value=\"$email\" class=\"email\"><br>";
echo "Your company:<br><input name=\"company\" type=\"text\" value=\"$company\"><br>";
echo "Membership no.:<br><input name=\"Membership_no\" type=\"text\" value=\"$Membership_no\"><br>";

echo "Subject:<br><input name=\"subject\" type=\"text\" value=\"$subject\" class=\"subject\"><br>";

echo "Message:<br><textarea name=\"message\" rows=4 cols=30 class=\"message\">$message</textarea>";
echo "<br><input type=\"submit\" value=\"Send\" class=\"submit\"></form>";

}
if(!$email&&!$message&&!$subject&&!$name) {

echo "<form name=\"theform\" method=\"get\" action=\"contact_fundi.php\">";

echo "Your name:</b><br><input name=\"name\" type=\"text\" value=\"$name\"><br>";
echo "Your e-mail:</b><br><input name=\"email\" type=\"text\" value=\"$email\"><br>";
echo "Your company:<br><input name=\"company\" type=\"text\" value=\"$company\"><br>";
echo "Membership no.:<br><input name=\"Membership_no\" type=\"text\" value=\"$Membership_no\"><br>";
echo "Subject:</b><br><input name=\"subject\" type=\"text\" value=\"$subject\"><br>";

echo "Message:</b><br><textarea name=\"message\" rows=4 cols=30>$message</textarea>";
echo "<br><input type=\"submit\" value=\"Send\" class=\"submit\"></form>";

}

?>
<!-- Put footers below here -->

</body>
</html>

nkokhi
05-08-2008, 01:06 AM
any idea?

umabindu
05-08-2008, 02:27 AM
hi i'm having problem with remeber me cookie, not working in IE6/IE7.Here is the code

login.php

<?php
session_start();

if(isset($_COOKIE["login_id"]))
{
$loginid=$_COOKIE["login_id"];
$uname=$_COOKIE[$loginid]["UNAME"];
$pwd=$_COOKIE[$loginid]["PASS"];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../images/gueststylesheet.css" rel="stylesheet" type="text/css">
<script language="javascript">
function loginin()
{
document.getElementById('UNAME').focus();
}
function login()
{
var uname = document.getElementById('UNAME').value;
var pass = document.getElementById('PASS').value;
if(!uname)
{
alert("Please Enter Username");
document.getElementById('UNAME').focus();
return false;
}


if(!pass)
{
alert("Please Enter Password");
document.getElementById('PASS').focus();
return false;
}
document.LoginPage.action="chk.php";
document.LoginPage.submit();
}
function keypress()
{
if(event.keyCode == '13')
{
login();
}
}
</script>
</head>

<body topmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:document.LoginPage.UNAME.focus();">
<form name='LoginPage' id='LoginPage' method='post' >
<table width="960" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
<tr>
<td height="109" valign="middle" background="../images/top_bg1.jpg">
<div align="left"><img src="../images/logo.jpg" width="287" height="109"></div></td>
</tr>
<tr>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="55%" valign="top"><img src="../images/login_image1.jpg" width="535" height="411"></td>
<td width="45%" valign="top" background="../images/login_bg.jpg">
<div align="center">
<table width="315" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="265" height="86" valign="bottom" class="fontb"><img src="../images/userlogin.jpg" width="167" height="33"></td>
</tr>
<tr>
<td height="131"><TABLE class=table cellSpacing=0 cellPadding=0
width="100%" align=center bgColor=#ffffff
border=0>
<TBODY>

<TR>
<TD height=100> <TABLE cellSpacing=5 cellPadding=0 width="100%"
border=0>
<TBODY>

<tr>
<td align="center" width="100%"><?php if ($_GET["a"]==1)
echo "<span class='starfontsize'>Invalid Login! Please Try Again</span>";

if ($_GET["a"]==4)
echo "<span class='starfontsize'>Your Password has been sent to your Email ID.</span>";




?></td>
</tr>
<tr>
<td height="100"> <table width="100%" border="0" cellpadding="0" cellspacing="5">
<tr>
<td class="font"><div align="right">Username : </div></td>
<td><input type='text' maxlength="10" name='UNAME' id='UNAME' class="box1" style="width:75%"/></td>
</tr>
<tr>
<td class="font"><div align="right">Password
: </div></td>
<td><input maxlength="15" type='password' name='PASS' id='PASS' onkeypress='keypress()' class="box1" style="width:75%"/></td>
</tr>
<tr><td></td>
<td class="font"><input type="checkbox" name="check1"/> Remember Me</td>

</tr>
<table align="center">
<tr>
<td></td>
<td align="center"><input type='button' value='Login' class='button' name='loginin' id='loginin' onclick='login()'/></td>
</tr>
</table>
<tr>
<td align="center" class="ntxt1" ><a href="forgotpwd.php"><U><span class="guardcolor">Forgot Password?</span></U></a></td>
</tr>
<tr></tr>
</TBODY>
</TABLE></TD>
</TR>
</TBODY>
</TABLE></td>
</tr>
</table>
</div></td>
</tr>
</table> </td>
</tr>
</table>
</form>
</body>
</html>



chk.php

<?php
//ini_set('session.cookie_lifetime', 0);
//ini_set('session.gc_maxlifetime', 20);
session_start();




$username = $_POST['username']; // Gets the inputted username from the form
$password = $_POST['password']; // Gets the inputted password from the form
$time = time(); // Gets the current server time
$check = $_POST['check1']; // Checks if the remember me button was ticked

include("../config/connect.php");
$uname=$_REQUEST["UNAME"];
$pwd=$_REQUEST["PASS"];
$today=date("Y-m-d H:m:s");
$domain = GetHostByName($REMOTE_ADDR);
$query="insert into login_log(username,ip_addr,login_tmstp) values('$_POST[UNAME]','".$domain."','".$today."')";
mysql_query($query) or die ('Error: ' . mysql_error());
$sql="select * from users where username='".$uname."' and password='".$pwd."'";
$admin_rec=mysql_query($sql) or die ('Error: ' . mysql_error());
$admin=mysql_fetch_object($admin_rec);
if(mysql_num_rows($admin_rec)=='1')
{
session_start();
//$_SESSION["login_id"]=$admin->login_id;
$_SESSION["user_id"]=$admin->user_id;
$_SESSION["emailid"]=$admin->emailid;
$_SESSION["user_type"]=$admin->user_type;
$_SESSION["username"]=$uname;
$_SESSION["FirstName"]=$admin->FirstName;
$_SESSION["LastName"]=$admin->LastName;
$_SESSION["password"]=$pwd;




if(isset($check))
{
// Check to see if the 'setcookie' box was ticked to remember the user
setcookie("login_id[username]", $username, $time + 6*30*24*3600); // Sets the cookie username
setcookie("login_id[password]", $password, $time + 6*30*24*3600); // Sets the cookie password
}

header("location:../news.php");
}
else
{

header("location:login.php?a=1");
}

?>

nkokhi
05-09-2008, 06:15 AM
What does this have to do with my question?