Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2012, 12:07 PM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Unhappy PHP Mail Problem!

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
angelali is offline   Reply With Quote
Old 02-20-2012, 12:13 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
You need to set up the smtp details in your php.ini file
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 02-20-2012, 12:14 PM   PM User | #3
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Can you help me for that? Please, I am still learning PHP.
angelali is offline   Reply With Quote
Old 02-20-2012, 12:22 PM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
In your c:\xampp\apache\bin\php.ini file, around line 700:
Code:
[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.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Users who have thanked Nightfire for this post:
angelali (02-20-2012)
Old 02-20-2012, 12:32 PM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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...
angelali is offline   Reply With Quote
Reply

Bookmarks

Tags
form, mail, validation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Advertisement
Log in to turn off these ads.