php form error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cyjetsu
Forum Newbie
Posts: 11
Joined: Fri Aug 29, 2008 2:13 am

php form error

Post by cyjetsu »

I have setup a basic php and html form on my local virtualhost(apache). When I click submit button I get 2 errors:

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:\operator1\on-infosol\primary\contact\form.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at C:\operator1\on-infosol\primary\contact\form.php:6) in C:\operator1\on-infosol\primary\contact\form.php on line 7


This is the html code.
<form action="form.php" method="POST">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="mesg"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="SubmitForm" value="Send"></td>
</tr>
</table>
</form>

and this is php code inside form.php:
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "nick6r6r66@hotmail.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>

Do I need to install some kind of program to send mail from on my local apache server? Or is a standard apache installation capable of doing so.... how?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php form error

Post by califdon »

Apache does not send mail, it is a web server. You need to install SMTP if you want to send mail from your localhost.

Headers can only be sent before any other output has been sent to the browser. You might want to do something like this:

Code: Select all

...
echo "Your email has been sent. Click <a href='http://example.com/thankyou.html'>here</a> to continue.";
Cut
Forum Commoner
Posts: 39
Joined: Sat Aug 23, 2008 8:01 pm

Re: php form error

Post by Cut »

That's a spam exploit waiting to happen to. Sanitize it for newlines or spammers will be able to use it to send email to anyone en masse.

Code: Select all

if (strstr($whatever, "\n") || strstr($whatever, "\r")) {
 $a = array("\n", "\r");
 str_replace($a, ' ');
}
You might want to do something like this:
Alternatively, use ob_start().
cyjetsu
Forum Newbie
Posts: 11
Joined: Fri Aug 29, 2008 2:13 am

Re: php form error

Post by cyjetsu »

Thanks I have not looked at security issues yet but any more tips or code you can give me on that would be helpful.

I see. I understand now that I have to setup and configure a local. SMTP mail server. Is it approximately as easy as setting up apache and php or is it a whole lot more complicated? If so, then I may just test my forms on my webhost -who I assume has a mail server already setup that will be very quick to configure for my form.
cyjetsu
Forum Newbie
Posts: 11
Joined: Fri Aug 29, 2008 2:13 am

Re: php form error

Post by cyjetsu »

I understand now.
I am trying to install iis and smtp on xp home now. I am having trouble finding what files i need to install and configure to make iis+smtp work on xp home.
cyjetsu
Forum Newbie
Posts: 11
Joined: Fri Aug 29, 2008 2:13 am

Re: php form error

Post by cyjetsu »

Do I need to use IIS? I already have apache and php running so is there an apache module for smtp that works on xp home?
cyjetsu
Forum Newbie
Posts: 11
Joined: Fri Aug 29, 2008 2:13 am

Re: php form error

Post by cyjetsu »

I have for the moment given up trying it on my local machine and now I am trying to get it to work on my webhost but they say this:

Is PHP mail() enabled on your hosting servers?
Answer


No, the PHP mail() function is not enabled on our hosting servers. This is due to the fact the function is not able to send mail using SMTP authorization with a username and password.

You may be able to toggle your PHP script to use a method to send mail that does send a username and password to the SMTP server.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php form error

Post by califdon »

cyjetsu wrote:Do I need to use IIS? I already have apache and php running so is there an apache module for smtp that works on xp home?
No, IIS is Microsoft's web server, essentially like Apache. Microsoft's mail server is Exchange Server, but you don't need any of those to install SMTP. You might consider this: http://www.softstack.com/freesmtp.html.

I'm not sure about your web host's messages. My experience has been that most web hosts do provide an SMTP server and support PHP's mail().
Post Reply