Link to home
Start Free TrialLog in
Avatar of JackShuker
JackShukerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Php contact us form doesnt work on php5 server

Hi Experts,

This is probably a easy one for you experts but im not very good with php, What is it we have a contact us form which is php and has worked on previous hosting sites, now we've just switched hosting which uses PHP5 and i can't figure out why the php contact form doesn't work.

The server idicates its something to do with this line:

$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";

Please bear with me as im new to php

Can you please let me know what i've done wrong or any advise?
<?php 
if ($_POST["email"]<>'') { 
	$ToEmail = 'something@something.co.uk'; 
	$EmailSubject = 'Site contact form '; 
	$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
	$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
	$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
	mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?> 
Your message was sent
<?php 
} else { 
?> 
<form action="contact_us.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext">&nbsp;</td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form> 
<?php 
}; 
?>

Open in new window

Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

It is working fine here,
what kind of an error do you get?
Avatar of Beverley Portlock
Put this at the top

<?php 
[b]ini_set('display_errors',1);   error_reporting(E_ALL);[/b]
if ($_POST["email"]<>'') { 
	$ToEmail = 'something@something.co.uk'; 
	$EmailSubject = 'Site contact form '; 
	$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
	$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
	$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
	mai

Open in new window


and see if any error messages pop up.
Arrghhhh it coded my tags........  I should have previewed it!

<?php
ini_set('display_errors',1);   error_reporting(E_ALL);
if ($_POST["email"]<>'') {
      $ToEmail = 'something@something.co.uk';
      $EmailSubject = 'Site contact form ';
      $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
      $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
      $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>";
      ....etc
Avatar of JackShuker

ASKER

on the site i get

Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 343

and line 343 is this line $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";

will add the ini_set('display_errors',1);   error_reporting(E_ALL); now and come back
ok added the ini_set and tested it and got this:
Notice: Undefined variable: mailheader in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 350

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 350
Failure

now line 350 is:
<?php
thats all

Have you switched from a Linux server to a Windows one?
Where is $mailheader being set? I don't see that anywhere and yet it is a parameter to your mail() function and the "From:" header is mentioned in the error message.

Mail under PHP/Windows is more complicated than under Linux - most LAMP servers come with the MTA pre-installed but on Windows you have to set it up and since I never, ever use Windows you will need input from someone who does use it.
Ok i've deleted the $mailheader as you stated its not set and shouldnt be there,
the error i get now after sending a test email is:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 350
Failure

It was from a php/windows to a php/windows the only differance is the new one is php5

im not sure what the error means by [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing etc am i missing something? or how do i set the php ini,

Sorry im not very technical
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That has worked fantastically, im able to receive emails off it now,
Just one more thing I have this on the same page and i dont know why, this is before I send a message :

Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 344

Now line 344 is:
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";

Why am I receiving this, btw you’ve been great im just sorry im not very knowledgeable in this area

Btw i have increased the points as you've been incredibly helpful
"Undefined index" notices pop up in PHP all the time. It just means that when you execute this

$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";

the array $_POST does not have an entry whose key is "name". Notices will not stop a script executing and is $_POST['name'] does not exist then PHP assigns a null string in its place so you get a gap where you expected data.

Remember to remove or comment out the ini_set('display_errors',1);   error_reporting(E_ALL); you added earlier.
i have to apologise as i am a n00b so how do i stop the

Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co.uk\user\htdocs\contact_us.php on line 344 from coming up then?

And thank you for reminding me about the ini_set i would have forgotten otherwise

Many thanks again
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for all of your help bportlock. have a lovely weekend
Have a good weekend yourself. Thanks!