# Feedback form in PHP not working - please help me debug it



## Zazula (Apr 27, 2006)

This is my feedback form in PHP. It works OK as far as completing the HTTP form is concerned; it also gives the error page when a box remains blank or the thankyou page when the form gets completed successfully. However, absolutely no e-mail is composed and sent to the address I've put in it. Is it a bug in the PHP file, or may be I have to set something in my hosting server (awardspace.com) that I'm unaware of? Many thanks in advance!

```
<?

$mailto = "[email protected]" ;

$subject = "Smartbank New Contact Form" ;

$formurl = "http://www.foxter.biz/contact.html" ;
$errorurl = "http://www.foxter.biz/error.html" ;
$thankyouurl = "http://www.foxter.biz/thankyou.html" ;

$uself = 0;


$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$surname = $_POST['surname'] ;
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$mobile = $_POST['mobile'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (empty($surname) || empty($name) || empty($phone) || empty($mobile) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if ( ereg( "[\r\n]", $surname ) || ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $phone ) || ereg( "[\r\n]", $mobile ) || ereg( "[\r\n]", $email ) ) {
	header( "Location: $errorurl" );
	exit ;
}

if (get_magic_quotes_gpc()) {
	$comments = stripslashes( $comments );
}

$messageproper =

	"This message was sent from:\n" .
	"$http_referrer\n" .
	"------------------------------------------------------------\n" .
	"Surname of sender: $surname\n" .
	"Name of sender: $name\n" .
	"Phone of sender: $phone\n" .
	"Mobile of sender: $mobile\n" .
	"Email of sender: $email\n" .
	"------------------------- COMMENTS -------------------------\n\n" .
	$comments .
	"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
	"From: \"$surname\" <$email>" . $headersep . "Reply-To: \"$surname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>
```


----------



## Deckard (May 8, 2006)

Sounds silly, but what does 


```
<?php 
  printf("%s\n%s\n%s\n", 
          ini_get('sendmail_path'), 
          ini_get('SMTP'),
          ini_get('smtp_port'); 
?>
```
produce? If none of those are set, or are set wrong, that may be why mail is not working.


----------



## Zazula (Apr 27, 2006)

OK, bear with me please, Deckard, coz I know zip about php.
The part you posted has to be included in my code or should I run it and see what it produces?
And, if I am to run it, how should I do that?


----------



## Deckard (May 8, 2006)

No problem -- I grok this stuff all day at work.

You can copy that in a separate file, say *t.php*, and upload that to the server if you can. Then just browse to it like you would any other script. I imagine the URL might be http://www.foxter.biz/t.php since that's where your feedback.php file is.

If that doesn't work, try using 


```
<?php phpinfo(); ?>
```
in a file by itself, but that may confuse you as it will list every PHP setting on the server. :grin:


----------



## Zazula (Apr 27, 2006)

Thanks a million, Deckard, I did as instructed and this message was returned:


> *Parse error:* parse error, unexpected ';' in */home/www/foxter.biz/t.php *on line *5*


That means the SMTP port is not set?
How on earth does one set this thing?


----------



## Deckard (May 8, 2006)

:doh:

I forgot a )


```
<?php 
  printf("Path: [%s]\nSMTP: [%s]\nPort: [%s]\n", 
          ini_get('sendmail_path'), 
          ini_get('SMTP'),
          ini_get('smtp_port')); 
?>
```
I should test instead of flying by the seat of my pants. :grin:

If these are set incorrectly, you may have to contact your hosting company to get the right values. I can only guess at them, and I'd probably get them wrong.

You can set PHP configuration values using ini_set(), but your hosting company should have them set for you already. :4-dontkno


----------



## Zazula (Apr 27, 2006)

OK, thanks again, I ran it and got this:


> Path: [/usr/bin/sendmailc] SMTP: [localhost] Port: [25]


Now what?


----------



## Deckard (May 8, 2006)

sendmail*c* is not what I would usually expect.

Try this:


```
<?php

// Test normal setup first
$address = '[email protected]';  // REPLACE WITH YOUR EMAIL ADDRESS

$a = mail($address, 'testing mail -- a', 'This is just a simple test (a)');
$b = mail($address, 'testing mail -- b', 'This is just a simple test with from (b)', "From: $address");

printf("a returned %u<br>", $a);
printf("b returned %u<br>", $b);

// Try some normal sendmail locations
if(file_exists('/usr/bin/sendmail')) {
	ini_set('sendmail_path', '/usr/bin/sendmail -t -i');
} elseif 	(file_exists('/usr/sbin/sendmail')) {
	ini_set('sendmail_path', '/usr/sbin/sendmail -t -i');
} elseif	(file_exists('/usr/lib/sendmail')) {
	ini_set('sendmail_path', '/usr/lib/sendmail -t -i');
} else {
	die("Unable to find a sendmail in the normal location.");
}

$c = mail($address, 'testing mail -- c', 'This is just a simple test (c)');
$d = mail($address, 'testing mail -- d', 'This is just a simple test with from (d)', "From: $address");

printf("c returned %u<br>", $c);
printf("d returned %u<br>", $d);
printf("<br>sendmail_path is %s<br>", ini_get('sendmail_path'));
?>
```


----------



## Zazula (Apr 27, 2006)

It gave back this:


> a returned 1
> b returned 1
> c returned 1
> d returned 1
> ...


----------



## Deckard (May 8, 2006)

Hmm.

Sorry it took so long to get back. I had to work today and I wanted to sit down and really look at this problem.

As far as I can tell, your feedback.php is fine. I was able to mail myself using it in my test environment.

It looks like you can't change the configuration, but the mail() function is definitely sending mail.

This may be something to take up with your hosting company. :4-dontkno


----------



## Zazula (Apr 27, 2006)

Hmm, now I'm really doomed... :4-toilet:
Being a downright cheapie, I have a free-hosting plan from Awardspace, which does not include any kind of support... I'll search around the various control panels that I get when I log in my account as a last resort that I'll eventually find something. What should I be looking for, anyhow (not only a cheapie, but a doofus as well - dammit!)?
And, Deckard, thank you very much for your help and support!


----------

