Thank you for taking the time to review my question.
I have postfix set up on Centos 6.4 I am not very familiar with E-mail servers or PHP, but I would like to set up a simple sight to send emails using postfix. I was told I should use php. My current. (not working) source code is this...
<!doctype html>
<html>
<head>
<style type="text/css">
#mainContainer
{
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#adressContainer
{
width:100%;
height:3%;
}
#buttonContainer
{
width:100%;
height:5%;
}
#bodyContainer
{
width:100%;
height:90%;
}
#address
{
resize:none;
width:100%;
height:100%;
}
#bodyText
{
resize:none;
width:100%;
height:100%;
}
</style>
<script>
<?php
function sendMail()
{
$to = "someone#somewhere"
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
?>
</script>
<!--<link rel="stylesheet" type="text/css" href="email.css" />-->
</head>
<body>
<div id="mainContainer">
<div id="addressContainer">
<input id="adress" type="text" name="Adress: "></input>
</div>
<div id="buttonContainer">
<button type="submit" onclick="sendMail()">send</button>
</div>
<div id="bodyContainer">
<textarea id="bodyText">I love you whitney :) </textArea>
</div>
</div>
</body>
</html>
PHP runs on the server. onClick executes Javascript on the CLIENT machine. You can NOT directly invoke PHP functions via Javascript code, or vice versa.
What you're doing can be accomplished with a simple form:
<?php
if ($_SERVER["REQUEST_METHOD"] == 'POST') {
$to = $_POST['to'];
$text = $_POST['text'];
mail($to, .....);
}
?>
<form method="POST" action="">
<input type="text" name="to" />
<input type="text" name="text" />
<input type="submit" />
</form>
There is no need to use Javascript at all.
Related
I am making a PHP project and am trying to change an input boxes value according to a PHP variable, how would I do this? So far, when I try to change the input boxes value it just changes the value to the name of the variable.
Here's the html for that section:
echo '
<html>
<title>Ramen</title>
<body>
<h1>
<p>Welcome to NoteBook!</p>
<form method="post">
<p>File Name:<input type="text" name="fname"></p>
<p>Type Here:<input type="text" name="content" id="TextBox" value="<?php echo $value; ?>"><p>
<p>Save:<input type="submit" value="Save"></p>
</form>
<form method="post">
<p>File to Open: <input type="text" name="filename"></p>
<input type="submit" value="Open">
</form>
</h1>
</body>
<style>
body{
background-color:#66b3ff;
}
p{
margin-left:30px;
}
h1{
background-color:white;
height:600px;
border-radius:1px;
font-size:18px;
font:italic;
}
#TextBox{
height:500;
width:700;
}
{
</style>
</html>```
$value doesn't appear to be being set anywhere.
I'm also a little confused as to why you have two <form>s.
As a starter, you need to parse the values coming in from the form, for example:
<?php
if (isset($_POST["filename"]) { // The $_POST variables are set using the name element of the <input> tag
$value = $_POST["filename"]
}
?>
You would likely want to do some more validation on the content of $_POST["value"] before accepting it.
Perhaps take a look at this example to get you started.
I leave you a possible example with explanation.
Besides, I have adapted the HTML structure a bit, since it has serious formatting problems. I advise you to read the manual on how to use the labels.
I added the name attribute to the submit, in order to know if the form is defined:
<input type="submit" name="save_data" value="Save">
Example:
<?php
// reset ¡important! (avoid warning <b>Warning</b>: Undefined variable etc..)
$file_name = $content = $txt_content = '';
// Recomended to check if the form is define
if (isset($_POST['save_data'])) {
// Get the inputs data
$file_name = $_POST['fname'] ?? '';
$content = $_POST['content'] ?? '';
// You can use textarea
$txt_content = $_POST['txt_content'] ?? '';
// Data is true
if ($file_name && $content && $txt_content) :
// Do somenting (ex: save it in DB)
//
//
$success = "Save correctly: $file_name";
// Data is empty (optional)
else :
$error = 'Te fields are empty.';
endif;
}
?>
<html lang="en-EN">
<head>
<title>Ramen</title>
<style>
body{
background-color:#66b3ff;
}
p {
margin-left:30px;
}
.wrapper {
background-color:white;
height:600px;
border-radius:1px;
font-size: 1rem;
font:italic;
padding: 1rem;
}
textarea {
height:200px;
width:400px;
}
.error {
color: red;
}
.success {
color: green;
}
</style>
</head>
<body>
<div class="wrapper">
<h1>Welcome to NoteBook!</h1>
<form method="post">
<lable for="fname">File Name:</lable>
<input type="text" name="fname" id="fname" value="<?php echo $file_name; ?>"></p>
<label for="content">Type Here:</label>
<input type="text" name="content" id="content" value="<?php echo $content; ?>">
<!-- for the content you could use the textarea tag -->
<textarea name="txt_content"><?php echo $txt_content; ?></textarea>
<input type="submit" name="save_data" value="Save">
<?php if (isset($error)) echo '<p class="error">' . $error . '</p>'; ?>
<?php if (isset($success)) echo '<p class="success">' . $success . '</p>'; ?>
</form>
</div>
</body>
</html>
Contact Form on my website stopped working after adding implementing SSL, it's PHP based and was working fine for 5 years before when it was just http.
Now when the form is filled correctly the message *"Sorry! Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field completed, and please also address any issues listed below:" keeps appearing.
It might be a simple issue but I don't know PHP and found this on a tutorial - would really help if anyone point out the issue and how to resolve it.
I can provide more details if needed.
Thanks!!
<?php
// Information to be modified
$your_email = "mail#website.com"; // email address to which the form data will be sent
$subject = "Visitor Message from Website"; // subject of the email that is sent
$thanks_page = "thankyou.htm"; // path to the thank you page following successful form submission
$contact_page = "../contact.htm"; // path to the HTML contact page where the form appears
// Nothing needs to be modified below this line
if (!isset($_POST['submit'])) {
header( "Location: $contact_page" );
}
if (isset($_POST["submit"])) {
$nam = $_POST["name"];
$ema = trim($_POST["email"]);
$com = $_POST["comments"];
$spa = $_POST["spam"];
if (get_magic_quotes_gpc()) {
$nam = stripslashes($nam);
$ema = stripslashes($ema);
$com = stripslashes($com);
}
$error_msg=array();
if (empty($nam) || !preg_match("~^[a-z\-'\s]{1,60}$~i", $nam)) {
$error_msg[] = "The name field must contain only letters, spaces, dashes ( - ) and single quotes ( ' )";
}
if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) {
$error_msg[] = "Your email must have a valid format, such as name#mailhost.com";
}
$limit = 1000;
if (empty($com) || !preg_match("/^[0-9A-Za-z\/-\s'\(\)!\?\.,]+$/", $com) || (strlen($com) > $limit)) {
$error_msg[] = "The Comments field must contain only letters, digits, spaces and basic punctuation ( ' - , . ), and has a limit of 1000 characters";
}
if (!empty($spa) && !($spa == "4" || $spa == "four")) {
echo "You failed the spam test!";
exit ();
}
// Assuming there's an error, refresh the page with error list and repeat the form
if ($error_msg) {
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
<style>
body {background: #f7f7f7; font: 100%/1.375 georgia, serif;padding: 20px 40px;}
form div {margin-bottom: 10px;}
.content {width: 40%; margin: 0 auto;}
h1 {margin: 0 0 20px 0; font-size: 175%; font-family: calibri, arial, sans-serif;}
label {margin-bottom: 2px;}
input[type="text"], input[type="email"], textarea {font-size: 0.75em; width: 98%; font-family: arial; border: 1px solid #ebebeb; padding: 4px; display: block;}
input[type="radio"] {margin: 0 5px 0 0;}
textarea {overflow: auto;}
.hide {display: none;}
.err {color: red; font-size: 0.875em; margin: 1em 0; padding: 0 2em;}
</style>
</head>
<body>
<div class="content">
<h1>Sorry!</h1>
<p>Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field completed, and please also address any issues listed below:</p>
<ul class="err">';
foreach ($error_msg as $err) {
echo '<li>'.$err.'</li>';
}
echo '</ul>
<form method="post" action="', $_SERVER['PHP_SELF'], '">
<div>
<label for="name">Name</label>
<input name="name" type="text" size="40" maxlength="60" id="name" value="'; if (isset($_POST["name"])) {echo $nam;}; echo '">
</div>
<div>
<label for="email">Email Address</label>
<input name="email" type="email" size="40" maxlength="60" id="email" value="'; if (isset($_POST["email"])) {echo $ema;}; echo '">
</div>
<div>
<label for="comm">Comments</label>
<textarea name="comments" rows="10" cols="50" id="comm">'; if (isset($_POST["comments"])) {echo $com;}; echo '</textarea>
</div>
<div class="hide">
<label for="spam">What is two plus two?</label>
<input name="spam" type="text" size="4" id="spam">
</div>
<div>
<input type="submit" name="submit" value="Send">
</div>
</form>
</body>
</html>';
exit();
}
$email_body =
"Name of sender: $nam\n\n" .
"Email of sender: $ema\n\n" .
"COMMENTS:\n\n" .
"$com" ;
// Assuming there's no error, send the email and redirect to Thank You page
if (isset($_REQUEST['comments']) && !$error_msg) {
mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>");
header ("Location: $thanks_page");
exit();
}
}
I m trying to display retrieved data from the database in the earlier created text area. Code is supposed to get users nickname and input message, store both in database and retrieve it back to text area, smth similar to one man chat (whatever is typed after clicking 'Send message' should be stored to database and retrieved and shown in the text area). I am able to store into my database and display retrieved data anywhere outside the text area. Any help appreciated. Thank you!
Code:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="postmessage.php">
<center>
<br />
<label for="output">Chat history</label>
<br />
<textarea name="output" cols="100" rows="25" id="output"></textarea>
<br />
<label for="nickname" maxlength="16">Nickname</label>
<br />
<input type="text" name="nickname" id="nickname" />
<br />
<label for="message" >Type your message here:</label>
<br />
<input name="message" type="text" id="message" size="87" /><input type="submit" value="Send Message" />
</form>
<?php
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('messenger', $connection);
$query = mysql_query('select * from messages');
while ($entry = mysql_fetch_object($query))
{
printf("<p>%s <br />- <em>%s</em></p>",
htmlentities($entry->message),
htmlentities($entry->nickname)
);
}
?>
</body>
</html>
postmessage.php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<?php
$nickname=$_POST['nickname'];
$message = $_POST['message'];
$nickname = mysql_real_escape_string($nickname);
$message = mysql_real_escape_string($message);
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('messenger', $connection);
if (!mysql_query(
"insert into messages (nickname, message) VALUES ('$nickname', '$message')"
)){
echo ("Could not process your send request");
};
?>
<body>
</body>
</html>
UPDATED:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="postmessage1.php">
<div style="text-align: center;">
<br />
<label for="output">Chat history</label>
<br />
<textarea name="output" cols="100" rows="25" id="output"><?php if(isset($_SESSION['currentChat'])){ echo $_SESSION['currentChat']; }?></textarea>
<br />
<label for="nickname" maxlength="16">Nickname</label>
<br />
<input type="text" name="nickname" id="nickname" />
<br />
<label for="message" >Type your message here:</label>
<br />
<input name="message" type="text" id="message" size="87" /><input type="submit" value="Send Message" />
</div>
</form>
</body>
</html>
post..php:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<?php
session_start();
$nickname = isset($_POST['nickname'])?$_POST['nickname']:"";
$message = isset($_POST['message'])?$_POST['message']:"";
if(empty($nickname) || empty($message)){
// no data return to form
header("location: chatform.php");
}
$mysqli = new mysqli("localhost", "root", "", "messenger");
/* create a prepared statement */
if ($stmt = $mysqli->prepare("INSERT INTO messages (nickname, message) VALUES (?, ?)")) {
/* bind parameters for markers */
$stmt->bind_param("ss", $nickname, $message);
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
// Update Session
$_SESSION['nickname'] .= htmlentities($nickname);
$_SESSION['currentChat'] .= htmlentities($message);
// Redirect back to display content
header("Location: chatform.php");
?>
</body>
</html>
For your form, I suggest the following:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="postmessage.php">
<div style="text-align: center;">
<br />
<label for="output">Chat history</label>
<br />
<textarea name="output" cols="100" rows="25" id="output"><?php if(isset($_SESSION['currentChat'])){ echo $_SESSION['currentChat']; }</textarea>
<br />
<label for="nickname" maxlength="16">Nickname</label>
<br />
<input type="text" name="nickname" id="nickname" value="<?php echo $_SESSION['nickName']; ?>" />
<br />
<label for="message" >Type your message here:</label>
<br />
<input name="message" type="text" id="message" size="87" /><input type="submit" value="Send Message" />
</div>
</form>
</body>
</html>
Then in your Post handler, do this:
<?php
start_session();
$nickname = isset($_POST['nickname'])?$_POST['nickname']:"";
$message = isset($_POST['message'])?$_POST['message']:"";
if(empty($nickname) || empty($message)){
// no data return to form
header("location: chatform.php");
}
$mysqli = new mysqli("localhost", "root", "", "messenger");
/* create a prepared statement */
if ($stmt = $mysqli->prepare("INSERT INTO messages (nickname, message) VALUES (?, ?)")) {
/* bind parameters for markers */
$stmt->bind_param("ss", $nickname, message);
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
// Update Session
$_SESSION['nickName'] = htmlentities($nickname);
$_SESSION['currentChat'] .= htmlentities($message);
// Redirect back to display content
header("Location: chatform.php");
?>
Taking this further, you can add TimeStamps via JS and you can use AJAX to post the data instead of using the form. Just drop the redirects and the session data. Also if the user closes the browser by accident, and returns, it should re-populate the data if the session is still alive.
Could also compile the chat and autosave it into DB every min or so instead of every chat action. Adding a leave button can kill the session and save everything to the DB at that time. Lots of ways to do it.
Code above is untested.
EDIT after comments
For your Chat page, I suggest changing the textarea to a div for better style control. Here is an example of the style: http://jsfiddle.net/Twisty/8frqcyyk/
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style>
.chatForm {
background: #ccc;
border: 1px solid #000;
width: 40em;
}
.chatForm ul {
padding: 0;
width: 30em;
margin: 5px auto;
}
.chatForm ul li {
list-style: none;
}
.chatForm ul li label {
display: block;
font: 1em Verdana, sans-serif;
}
.chatForm label.title {
background: #222;
border: 3px solid #222;
color: #FFF;
display: block;
font: 1em Verdana, sans-serif;
height: 1.5em;
margin: 0px auto;
width: 30em;
}
.center {
text-align: center;
}
.chatHistory {
background: #fff;
border: 1px inset #DDD;
display: block;
font: 1em Verdana, sans-serif;
height: 15em;
margin: 0px auto;
overflow-y: scroll;
padding: 2px;
text-align: left;
width: 30em;
}
.chatHistory p {
margin: 5px 0;
}
.chatHistory label {
display: inline-block;
font: bold 0.85em Arial, sans-serif;
width: 100px;
}
.chatHistory label.senderName {
color: blue;
}
.chatHistory label.nickName {
color: red;
}
.messageText {
width: 75%;
}
input[type='submit'] {
font: .85em Arial, sans-serif;
width: 20%;
}
</style>
</head>
<body>
<form method="post" action="postmessage.php">
<div class="chatForm">
<label for="output" class="center title">Chat History</label>
<div id="output" class="chatHistory">
<?php echo $_SESSION['currentChat']; ?>
</div>
<ul>
<li>
<label for="nickname">Nickname</label>
<input type="text" name="nickname" id="nickname" value="<?php echo $_SESSION['nickName']; ?>" />
</li>
<li>
<label for="message">Type your message here:</label>
<input name="message" type="text" id="message" class="messageText" /><input type="submit" value="Send" /></li>
</ul>
</div>
</form>
</body>
</html>
A few changes for your Post handler too (that should not be wrapped in HTML):
<?php
session_start();
$nickname = isset($_POST['nickname'])?$_POST['nickname']:"";
$message = isset($_POST['message'])?$_POST['message']:"";
if(empty($nickname) || empty($message)){
// no data return to form
header("location: chatform.php");
}
$mysqli = new mysqli("localhost", "root", "", "messenger");
/* create a prepared statement */
if ($stmt = $mysqli->prepare("INSERT INTO messages (nickname, message) VALUES (?, ?)")) {
/* bind parameters for markers */
$stmt->bind_param("ss", $nickname, $message);
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
// Update Session
$_SESSION['nickname'] .= htmlentities($nickname);
$results = $mysqli->query("SELECT * FROM messages");
$updateChat = "";
while($row = $results->fetch_assoc()){
$updateChat .= "<p><label>". htmlentities($row['nickname'] .":</label>";
$updateChat .= htmlentities($row['message']) . "</p>\r\n";
}
$results->free();
$mysqli->close();
$_SESSION['currentChat'] = $updateChat;
// Redirect back to display content
header("Location: chatform.php");
?>
If it were me, I would improve me DB schema. The table could include more columns: ID, DateStamp, Sender, Recipient, Message. Hope that helps, and again, untested.
I'm having some code show up on my mail php block. It has happened with every form tutorial I've gone through. Well, it works with the basic form, but when I try a form that adds a bit of security, I get code showing through.
I'm using a css template provided online as well as a php mail code found online as well. When I pull up the stand alone code in XAMPP it looks fine, but when I incorporate it into my html, the code bleeds through.
Help?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<link href='http://fonts.googleapis.com/css?family=Ruthie' rel='stylesheet' type='text/css'>
<!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Portraiture Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20130111 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>title</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.slidertron-1.1.js"></script>
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600%7CArchivo+Narrow:400,700" rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Ruthie" rel="stylesheet" type="text/css" />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]> <link href="default_ie6.css" rel="stylesheet" type="text/css" /> <![endif]-->
<link rel="stylesheet" type="text/css" href="active1.css" />
</head>
<body>
<div id="wrapper" class="container">
<div id="header">
<div id="logo">
<h1>maggie braner</h1>
</div>
</div>
<div id="menu">
<ul>
<li class="active">Home</li>
<li>Music Lessons</li>
<li>Pottery</li>
<li>Jazz Band</li>
</ul>
</div>
<div id="banner">
<div id="slider">
<div class="viewer">
<div class="reel">
<div class="slide"> <img src="images/pic01.jpg" alt="" height="570" width="505" /> </div>
<div class="slide"> <img src="images/pic02.jpg" alt="" height="500" width="900" /> </div>
</div>
</div>
</div>
<script type="text/javascript">
$('#slider').slidertron({
viewerSelector: '.viewer',
reelSelector: '.viewer .reel',
slidesSelector: '.viewer .reel .slide',
advanceDelay: 3000,
speed: 'slow'
});
</script>
</div>
<div id="page">
<div id="content">
<h2>Welcome!</h2>
<p> body text here </p>
</div>
<div id="sidebar">
<?php
$your_email ='yourname#your-website.com';// <<=== update to your email address
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
///------------Do Validations-------------
if(empty($name)||empty($visitor_email))
{
$errors .= "\n Name and Email are required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"Name: $name\n".
"Email: $visitor_email \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
header('Location: thank-you.html');
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact Us</title>
<!-- define some style elements-->
<style>
label,a, body
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
.err
{
font-family : Verdana, Helvetica, sans-serif;
font-size : 12px;
color: red;
}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p>
<label for='name'>Name: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
<label for='email'>Email: </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input type="submit" value="Submit" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>
</div>
</div>
</div>
<div id="footer">
<p>Copyright (c) 2012 Sitename.com. All rights reserved. Design
by FreeCSSTemplates.org,</br>
released under a <a href="http://creativecommons.org/licenses/by/3.0/">Creative
Commons Attributions 3.0</a> license</p>
</div>
</div>
</body></html>
i think you must put the session_start() in the very top of your page
RESOLVED.
I renamed the file from .html to .php and it worked fine as is.
Thank you all.
I'm having an issue with my php code. I'm using jquery to validate user input. When I click the submit button I recieve the email, but I cannot return to another page such as "it was successfully sent". I'm new to this and I'm not sure how to get help so I'm going to post the php page where it sends and where I cannot cant that it done so T.T
this page is called ajax.php
<?
#extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$telephone = stripslashes($telephone);
$message = stripslashes($message);
if(mail("mememe#hotmail.com","Email from $name","
$message
(From $name, $email, $telephone)","From: $email")){
echo "$name $email $telephone $message";
}
echo "Email Successfully Sent!<br />
<br />
Name: $name<br />Email: $email<br />telephone: $telephone<br />Message: $message";
?>
this page is the form with jquery validation "onblur" which im submitting from
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../style.css" rel="stylesheet" type="text/css" />
<script src="prototype.js" type="text/javascript"></script>
<script src="livevalidation.js" type="text/javascript"></script>
</head>
<body>
<div class="main">
<div class="footer_resize">
<div class="footer">
<div class="menu">
<ul>
<li>Home </li>
<li>Services</li>
<li>Contact Us</li>
</ul>
</div>
<div class="clr"></div>
</div>
</div>
<div class="clr"></div>
<div class="body">
<div class="body_resize">
<div class="left">
<h2>Contact for appointment</h2>
<p>
<strong>Address</strong>
<br />So Shiq Studio
<br />380 King Street North
<br />Waterloo ON
<br />Tel. 519.721.8060
<br /></p>
<p></p>
<p><strong>Hours of Operation</strong><br />
Tuesday: 10AM – 7PM <br />
Friday: 10AM – 8PM <br />
Saturday: 9AM – 3PM</p>
<p></p>
<p><strong>Private Appointments</strong><br />
Monday - Wednesday <br />
Colour Upon Consultation <br />
*Minimum 2 Services*</p>
<p><br />
</p>
<p>
<strong></strong><br />
</p>
</div>
<br /><br /><br />
<form id="my-form" style="padding-left:16.9em" >
<table class=shadow border="0" width="71%" style="background:#ececec; font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;" cellspacing="15">
<tr align="left"><td><strong>Full Name</strong></td><td><input type="text" size="50" id="name" name="name" style="font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;"></td></tr>
<tr align="left"><td><strong>Email Address</strong></td><td><input type="text" size="50" id="email" name="email" style="font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;"></td></tr>
<tr align="left"><td><strong>Phone Number</strong></td><td><input type="text" size="50" id="telephone" name="telephone" style="font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;"></td></tr>
<tr align="left"><td valign="top"><strong>Comments</strong></td><td><textarea id="message" name="message" rows="8" cols="80" style="font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;"></textarea></td></tr>
<tr align="left"><td> </td><td>
<input type="button" name:"clear" value="Send" onclick="sendRequest();" style="font:normal 12px Arial, Helvetica, sans-serif; color:#6b6b6b;font-weight:bold;"/></td></tr>
</table>
</form>
<script type="text/javascript">
var name = new LiveValidation( 'name' );
name.add( Validate.Presence );
var email = new LiveValidation( 'email' );
email.add( Validate.Presence );
email.add( Validate.Email );
var telephone = new LiveValidation( 'telephone' );
telephone.add( Validate.Presence );
telephone.add( Validate.Telephone );
var message = new LiveValidation( 'message' );
message.add( Validate.Presence );
function sendRequest(){
if(LiveValidation.massValidate( [ name, email, telephone, message ] )){
new Ajax.Request('ajax.php',
{
method:'post',
parameters: $('my-form').serialize(true),
onLoading: function(){
$('update_div').show();
$('update_div').innerHTML = "Sending...";
},
onSuccess: function(transport){
var response = transport.responseText || "No response text";
$('update_div').innerHTML = response;
},
onFailure: function(){
$('update_div').innerHTML = "Something went wrong...";
}
});
}
}
</script>
<br /><br /><br /><br />
<div class="clr"></div>
</div>
</div>
<div class="clr"></div>
<div class="clr"></div>
<div class="footer">
<div class="footer_resize">
<p class="leftt">
<img src="../images/rss_1.gif" alt="picture" width="18" height="16" border="0" />
<img src="../images/rss_2.gif" alt="picture" width="18" height="16" border="0" />
</p><p class="right"> © Copyright COSMO STEFAN All Rights Reserved </p>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</div>
</body>
</html>
ive tried what u both below suggested but i cannot get it working T.T. i know the code is messy, im really new to this and just trying to figure out what im doing wrong.. thank u soo much for ur help already.
Update
Using header()
To redirect a page using PHP, you use the header() function. This function is designed to send HTTP headers back to the client. If you send the HTTP Location header with a value, the client will more or less interpret that as meaning "Go to the page specified in the value".
To use the header function to redirect:
<?php
header('Location: http://www.yoursite.com/the/page/you/want/to/go/to.php?success=1');
exit();
?>
Note that I explicitly say exit() after issuing the call to header(). Any code after the header redirect will still be executed unless you exit.
Using $_GET
_GET is a superglobal in PHP. When PHP loads, it loads all of the variables it finds in the URL into this associative array. The example above sets a GET variable named success equal to 1. You can access the GET superglobal like this:
echo( $_GET['success'] );
You can use this to tell your calling page that your email has been sent by just checking to see if $_GET['success'] is set and equal to 1, then output your message.
<?php
if(isset($_GET['success']) && $_GET['success'] == 1)
echo( 'Email Successfully Sent!<br />' );
?>
There are more complicated ways of doing this, but this I believe is probably the easiest and quickest to implement. Be sure not to output anything before you issue the call to the header() function.
I have tidy up your code below. It should work
<?
#extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$telephone = stripslashes($telephone);
$message = stripslashes($message);
if(mail("mememe#hotmail.com","Email from". $name.$message))
{
echo "Email Successfully Sent!<br /><br />Name:". $name."<br />Email:". $email."<br />telephone:". $telephone."<br />Message:". $message;
}
?>
If you want to redirect to success page this is the code
<?
#extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$telephone = stripslashes($telephone);
$message = stripslashes($message);
if(mail("mememe#hotmail.com","Email from". $name.$message))
{
//echo "Email Successfully Sent!<br /><br />Name:". $name."<br />Email:". $email."<br />telephone:". $telephone."<br />Message:". $message;
header("location:http://www.yourdomain.com/success.html");
}
?>