Page 1 of 1

php form error

Posted: Fri Sep 05, 2008 5:12 pm
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?

Re: php form error

Posted: Fri Sep 05, 2008 5:27 pm
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.";

Re: php form error

Posted: Fri Sep 05, 2008 8:33 pm
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().

Re: php form error

Posted: Sat Sep 06, 2008 4:34 am
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.

Re: php form error

Posted: Sat Sep 06, 2008 6:25 am
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.

Re: php form error

Posted: Sat Sep 06, 2008 6:34 am
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?

Re: php form error

Posted: Sat Sep 06, 2008 7:20 am
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.

Re: php form error

Posted: Sat Sep 06, 2008 12:15 pm
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().