Hello I am having a problem with forms. I know they are easy for some people, but I am new. I am trying to make a simple feedback form. Hear is what I have so far...
[code=php]
<?php
//process the email
if (array_key_exis ts('send', $_POST)) {
$to = 'goldfishgraphi cs@gmail.com'; //use your own email
$subject = 'Project Idea';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Project Idea: $comments";
//limit line length to 55 characters
$message = wordwrap($messa ge, 55);
//send it
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Goldfi sh Graphics</title>
<link type="text/css" rel="stylesheet " href="Goldfish. css" />
<style type="text/css">
<!--
A {text-decoration:none }
-->
</style>
</head>
<body>
<div id="container" >
<div id="banner">
<img src="images/banner.jpg" alt= "Goldfish Graphics Banner Image" />
</div>
<div id="navigation" >
<div id="hvan">
<a href="index.php ">Home</a> <a href="services. php">Services</a> <a href="portfolio .php">Portfolio </a> <a href="contact.p hp">Contact</a>
</div>
</div>
<div id="sidebar">
<div id="texto">
<h4 class="sidebar" > Testimonies</h4>
<p>
<?php include('testmo nies.php'); ?>
</p>
</div>
<h4>Links</h4>
<div id="links">
<div class="nav">
<p>
<a href="#">Pixel2 Life</a>
<br />
<a href="#">Link</a>
<br />
<a href="#">Link</a>
<br />
<a href="#">Link</a>
</p>
</div>
</div>
</div>
<div id="content">
<div id="text">
<h2>Contact</h2>
<p id="home">
<form id="feedback" method="post" action="">
<p>
<label for="name">Name :</label>
<input name="security" id="security" type="text" class="name" />
</p>
<label for="email">Ema il:</label>
<input name="security" id="security" type="text" class="email" />
<p>
<label for="comments"> Prodject Description:</label>
<textarea name="security" id="security" cols="54" rows="5">
</textarea>
</p>
<p>
<input name="send" id="send" type="submit" value="Submit" />
</p>
</form>
<?php
if ($_POST && !$mailSent) {
?>
<p class="warning" >Sorry, there was a problem sending your message. Please check to make sure you filled out all the required entries.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p><strong>Yo ur message has been sent. Thank you.</strong></p>
<?php } ?>
</p>
<p id="news">
</p>
</div>
</div>
<div id="footer">
</div>
</div>
</body>
</html>[/code]
The problem is it's not actually sending anything to my email. This might be because I am doing it on a local host, the other thing is whenever I summit any kind of information this error message pops up at the top of my site...
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\Gol dfish Graphics\contac t.php on line 21
I want to know how to make that not happen, I want to know how to make the information actually go to my email, and I don't really understand how to make my forms safe from hackers. I basically went through a tutorial and found this.
[code=php]
<?
function secured($val)
{
if(empty($val) or strlen($val) > 40)
{
return false;
} else {
$val = strip_tags(
trim(($val)
)
)
;
$val = escapeshellcmd( $val);
return stripslashes($v al);
}
}
?>[/code]
I have that saved in a php file as security and in my code above you can see I have the name and id of the input fields as security. Does this work?
[code=php]
<?php
//process the email
if (array_key_exis ts('send', $_POST)) {
$to = 'goldfishgraphi cs@gmail.com'; //use your own email
$subject = 'Project Idea';
//process the $_POST variables
$name = $_POST['name'];
$email = $_POST['comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Project Idea: $comments";
//limit line length to 55 characters
$message = wordwrap($messa ge, 55);
//send it
$mailSent = mail($to, $subject, $message);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Goldfi sh Graphics</title>
<link type="text/css" rel="stylesheet " href="Goldfish. css" />
<style type="text/css">
<!--
A {text-decoration:none }
-->
</style>
</head>
<body>
<div id="container" >
<div id="banner">
<img src="images/banner.jpg" alt= "Goldfish Graphics Banner Image" />
</div>
<div id="navigation" >
<div id="hvan">
<a href="index.php ">Home</a> <a href="services. php">Services</a> <a href="portfolio .php">Portfolio </a> <a href="contact.p hp">Contact</a>
</div>
</div>
<div id="sidebar">
<div id="texto">
<h4 class="sidebar" > Testimonies</h4>
<p>
<?php include('testmo nies.php'); ?>
</p>
</div>
<h4>Links</h4>
<div id="links">
<div class="nav">
<p>
<a href="#">Pixel2 Life</a>
<br />
<a href="#">Link</a>
<br />
<a href="#">Link</a>
<br />
<a href="#">Link</a>
</p>
</div>
</div>
</div>
<div id="content">
<div id="text">
<h2>Contact</h2>
<p id="home">
<form id="feedback" method="post" action="">
<p>
<label for="name">Name :</label>
<input name="security" id="security" type="text" class="name" />
</p>
<label for="email">Ema il:</label>
<input name="security" id="security" type="text" class="email" />
<p>
<label for="comments"> Prodject Description:</label>
<textarea name="security" id="security" cols="54" rows="5">
</textarea>
</p>
<p>
<input name="send" id="send" type="submit" value="Submit" />
</p>
</form>
<?php
if ($_POST && !$mailSent) {
?>
<p class="warning" >Sorry, there was a problem sending your message. Please check to make sure you filled out all the required entries.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p><strong>Yo ur message has been sent. Thank you.</strong></p>
<?php } ?>
</p>
<p id="news">
</p>
</div>
</div>
<div id="footer">
</div>
</div>
</body>
</html>[/code]
The problem is it's not actually sending anything to my email. This might be because I am doing it on a local host, the other thing is whenever I summit any kind of information this error message pops up at the top of my site...
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\Gol dfish Graphics\contac t.php on line 21
I want to know how to make that not happen, I want to know how to make the information actually go to my email, and I don't really understand how to make my forms safe from hackers. I basically went through a tutorial and found this.
[code=php]
<?
function secured($val)
{
if(empty($val) or strlen($val) > 40)
{
return false;
} else {
$val = strip_tags(
trim(($val)
)
)
;
$val = escapeshellcmd( $val);
return stripslashes($v al);
}
}
?>[/code]
I have that saved in a php file as security and in my code above you can see I have the name and id of the input fields as security. Does this work?
Comment