angelali
02-20-2012, 12:07 PM
Hello, I am creating a website of mine, and have included a contact form in it! I am having problems when sending an email to test it. Below are my codes including validation and HTML:
HTML Codes
form action="#" method="post">
<p>Your full name (Required):</p>
<p><input type="text" size="35" placeholder="Your name here..." name="name"/></p>
<p>Subject (Required):</p>
<p><input type="text" size="35" placeholder="Subjecte..." name="subject"/></p>
<p>Your email address (Required):</p>
<p><input type="text" size="35" placeholder="Your email address..." name="email"/></p>
<p>Your message (Required):</p>
<p><textarea cols="66" rows="8" name="comments"></textarea></p>
<input class="submit" type="submit" value="Send" name="submit"/>
<input class="submit" type="reset" value="Reset"/>
</form>
PHP Codes
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
$fname = htmlentities($_POST['name']);
$subj = htmlentities($_POST['subject']);
$emailaddr = htmlentities($_POST['email']);
$message = htmlentities($_POST['comments']);
//Check if the form is submitted
if (isset($_POST['submit'])) {
if (empty($fname) || empty($emailaddr) || empty($subj)|| empty($message)) {
echo 'All fields must be filled!'.'<br/>';
return false;
}
elseif (filter_var($fname, FILTER_VALIDATE_INT)) {
echo 'Name must not be numbers'.'<br/>';
return false;
}
elseif (!filter_var($emailaddr, FILTER_VALIDATE_EMAIL)){
echo 'Invalid email'.'<br/>' ;
return false;
}
else {
mail("angel.ali201111@yahoo.com", "$subj",
$message, "From:" . $emailaddr);
echo "Thank you for using our mail form";
}
}
}
?>
The error I am having is this:
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 C:\xampp\htdocs\softwareportfolio\contact.php on line 44
Thank you for using our mail form
I am on local host, and I want to test it on localhost itself, so please help me! Thank
HTML Codes
form action="#" method="post">
<p>Your full name (Required):</p>
<p><input type="text" size="35" placeholder="Your name here..." name="name"/></p>
<p>Subject (Required):</p>
<p><input type="text" size="35" placeholder="Subjecte..." name="subject"/></p>
<p>Your email address (Required):</p>
<p><input type="text" size="35" placeholder="Your email address..." name="email"/></p>
<p>Your message (Required):</p>
<p><textarea cols="66" rows="8" name="comments"></textarea></p>
<input class="submit" type="submit" value="Send" name="submit"/>
<input class="submit" type="reset" value="Reset"/>
</form>
PHP Codes
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
$fname = htmlentities($_POST['name']);
$subj = htmlentities($_POST['subject']);
$emailaddr = htmlentities($_POST['email']);
$message = htmlentities($_POST['comments']);
//Check if the form is submitted
if (isset($_POST['submit'])) {
if (empty($fname) || empty($emailaddr) || empty($subj)|| empty($message)) {
echo 'All fields must be filled!'.'<br/>';
return false;
}
elseif (filter_var($fname, FILTER_VALIDATE_INT)) {
echo 'Name must not be numbers'.'<br/>';
return false;
}
elseif (!filter_var($emailaddr, FILTER_VALIDATE_EMAIL)){
echo 'Invalid email'.'<br/>' ;
return false;
}
else {
mail("angel.ali201111@yahoo.com", "$subj",
$message, "From:" . $emailaddr);
echo "Thank you for using our mail form";
}
}
}
?>
The error I am having is this:
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 C:\xampp\htdocs\softwareportfolio\contact.php on line 44
Thank you for using our mail form
I am on local host, and I want to test it on localhost itself, so please help me! Thank