View Full Version : PHP Mail Problem!

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"/>

PHP Codes

$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

02-20-2012, 12:13 PM
You need to set up the smtp details in your php.ini file

02-20-2012, 12:14 PM
Can you help me for that? Please, I am still learning PHP.

02-20-2012, 12:22 PM
In your c:\xampp\apache\bin\php.ini file, around line 700:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

Change SMTP to your ISP’s server and sendmail_from to your email address on the mail server.

02-20-2012, 12:32 PM
You ARE GREAT DUDE...YES it is working now... Now I can test my form. By the way, do you think by using "return false" in my codes above when validating is OK? Give me your opinions on my codes above...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum