PHP Mail Submit Form Error

This is a discussion on "PHP Mail Submit Form Error" within the PHP Forum section. This forum, and the thread "PHP Mail Submit Form Error are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 11th, 2007, 13:30
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Mail Submit Form Error

Hello! I am learning the basics on how to create a feed back form were users can compliment or complain about various subjects by filling in a form, and submitting the data to my email address.

The only problem is when i test the form i get a error messege in the browser explaining i need mail setting configured correctly, i am using XAMMP and and am a bit stuck on how to solve the problem. Below i have displayed my error messege and form & php code. Please help with this problem as a lot of the time when i post no one responds about what am stuck on!

Cheers.

My error:

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\WiKid\send_contact.php on line 23
ERROR

My form code:

HTML: Select all
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

My PHP Code:

PHP: Select all

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Contact subject
$subject ="$subject"
// Details
$message="$detail"
// Mail of sender
$mail_from="$customer_mail"
// From 
$header="from: $name <$mail_from>"
// Enter your email address
$to ='NeoReloaded@hotmail.co.uk'
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo 
"Baldy Has Just Recieved Yer moaning Assed Complaint";
}
else {
echo 
"ERROR";
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 11th, 2007, 14:54
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: PHP Mail Submit Form Error

Quote:
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
Those variables are not set.

PHP: Select all

$subject $_POST[subject];
$message $_POST[detail];
$mail_from $_POST[customer_mail]; 
The next step would be validate all of those fields before anything is done. Especially the email field. Look into form validation with PHP and Regular Expressions.

Good Luck,
Scott
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 11th, 2007, 15:08
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Mail Submit Form Error

Hello & thanks 4 the reply!

I have changed the variables and i am getting this error messege:




Notice: Use of undefined constant subject - assumed 'subject' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 12

Notice: Use of undefined constant detail - assumed 'detail' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 14

Notice: Use of undefined constant customer_mail - assumed 'customer_mail' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 17

Notice: Undefined variable: name in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 19
Bauld Has Just Recieved Yer Winging Assed Complaint


Here is how i alterd the variables:

PHP: Select all

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Contact subject
$subject $_POST[subject];
// Details
$message $_POST[detail];
// Mail of sender
$mail_from $_POST[customer_mail]; 
// From 
$header="from: $name <$mail_from>"
// Enter your email address
$to ='NeoReloaded@hotmail.co.uk'
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo 
"Bauld Has Just Recieved Yer Winging Assed Complaint";
}
else {
echo 
"ERROR";
}
?>

</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 11th, 2007, 15:31
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: PHP Mail Submit Form Error

Remember to declare all your variables. Your name variable is not declared, and I think that is where it encounters your error. Add this to the top of your PHP file.
PHP: Select all

$name $_POST[name]; 


Also restructure your file like this:

PHP: Select all

 
<?php
// Contact subject
$subject $_POST[subject];
// Details
$message $_POST[detail];
// Mail of sender
$mail_from $_POST[customer_mail]; 
// From 
$header="from: $name <$mail_from>"
// Enter your email address
$to ='NeoReloaded@hotmail.co.uk'
$send_contact=mail($to,$subject,$message,$header);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<$php 
      // Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo "Bauld Has Just Recieved Yer Winging Assed Complaint";
}
else {
echo "ERROR";
}
?>
</body>
</html>
Try that.

Scott
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 11th, 2007, 15:43
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Mail Submit Form Error

Ok I have decalred all the variables and still no luck!!

Its doin me head in!!

Below is my erorrs still:

Notice: Use of undefined constant name - assumed 'name' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 11
Notice: Use of undefined constant subject - assumed 'subject' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 15
Notice: Use of undefined constant detail - assumed 'detail' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 17
Notice: Use of undefined constant customer_mail - assumed 'customer_mail' in e:\domains\s\sexyencounters.net\user\htdocs\send_c ontact.php on line 20
Bauld Has Just Recieved Yer Winging Assed Complaint


Below is my php file called:

send_contact.php

PHP: Select all

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$name 
$_POST[name]; 
// Contact subject
$subject $_POST[subject];
// Details
$message $_POST[detail];
// Mail of sender
$mail_from $_POST[customer_mail]; 
// From 
$header="from: $name <$mail_from>"
// Enter your email address
$to ='NeoReloaded@hotmail.co.uk'
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo 
"Bauld Has Just Recieved Yer Winging Assed Complaint";
}
else {
echo 
"ERROR";
}
?>

</body>
</html>
Below is my php file:

contact.php

HTML: Select all
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Everythink looks correct, i just dont understand why it doesnt work!! Any other sugestions??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 11th, 2007, 15:59
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: PHP Mail Submit Form Error

Most developers put all the php processing instructions before any html. I would place all variables and processing instructions at the top of your document. Then echo a variable that contains the message either successful or unsuccessful. Also the use of a variable named header may be producing an error as header is a php function.
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 11th, 2007, 16:02
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Mail Submit Form Error

I think you may be better testing this live as your host will have the mail function set up and you will be able to see the errors you really need sorting.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] parse error, unexpected T_EXIT in php mail script Posie PHP Forum 8 Dec 13th, 2007 14:21
PHP Form returns error : mail expects most 5 parameters? shifty PHP Forum 5 Sep 30th, 2007 21:07
Mail Form help! ClrWtrDsgnr PHP Forum 6 Sep 27th, 2007 21:22
submit many forms - auto submit the same form many times divs JavaScript Forum 0 May 24th, 2007 10:10
visitors name not displayed in mail after filling in mail form made on earth PHP Forum 7 Nov 16th, 2005 22:43


All times are GMT. The time now is 02:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42