JackShuker
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?
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"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
?>
Put this at the top
and see if any error messages pop up.
<?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
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
<?php
ini_set('display_errors',1
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"])
....etc
ASKER
on the site i get
Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co .uk\user\h tdocs\cont act_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
Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co
and line 343 is this line $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
will add the ini_set('display_errors',1
ASKER
ok added the ini_set and tested it and got this:
Notice: Undefined variable: mailheader in E:\Domains\c\cabmakerfs.co .uk\user\h tdocs\cont act_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\h tdocs\cont act_us.php on line 350
Failure
now line 350 is:
<?php
thats all
Notice: Undefined variable: mailheader in E:\Domains\c\cabmakerfs.co
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\Domains\c\cabmakerfs.co
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.
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.
ASKER
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\h tdocs\cont act_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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\h tdocs\cont act_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
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
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.
$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
ASKER
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\h tdocs\cont act_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
Notice: Undefined index: email in E:\Domains\c\cabmakerfs.co
And thank you for reminding me about the ini_set i would have forgotten otherwise
Many thanks again
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much for all of your help bportlock. have a lovely weekend
Have a good weekend yourself. Thanks!
what kind of an error do you get?