Hi I want to make a contact form but I am having some trouble. I always use the same code for a simple form, but on a new site with a new host, it doesnt work. I have no idea why. I turn CGI on already. here is the code. PHP file: <? $to = "xxx@xxxx.com"; $subject = "Email from website contact form"; $boundary = uniqid(""); $headers = "From: $from"; $body = " Name :$user Email :$emailaddress Comment :$comments "; if (mail($to, $subject, $body,$headers)) { print( "Thank you for emailing us.Your file has been sent succesfully"); ?> <meta http-equiv=refresh content="1;URL=http://www.peacefulseasangha.com/sampleforliz/files/CUT H.html"> <? } else { print( "Error: Unknown error ocurred. The message could not be sent. Please try again later.\n"); } ?> and here is the code from the html file: "... Contact FORM </div> <div id="cu"> Please use the form below to send us email. Thank You. <div id="flabels"> <br>Name: <br>Email: <br>Comments: </div> <div id="fitems"> <br> <form name="form1" method="post" action="mail_t.php"> <input type="text" name="user" size="25"> <input type="text" name="emailaddress" size="25"> <textarea cols="10" rows="4" name="comments"></textarea> <input type="submit" value="Send"> </form> </div> ..." I use the exact same code on many sites but this new site it just doesnt work with it. Does anyone have any idea what could be the reason? Trying to send to an email address on the domain. I receive no email, no error msg, nothing. Thanks. Sami
mail functions have requirements ... refer to this link and perhaps you could ask about them from your host http://www.php.net/manual/en/ref.mail.php
I think there can be a easy solution. If you type $_POST['from'] and not $from i think it can work better. This feature of using $from is disabled in later versions of php due to security(this is on all fields in the form $_POST['subject'] etc)
Hi thanks for the comments. I have been actually advised to do that before but didnt know how to, your explanation looks like I can understand , thanks I'll give it a try. Sami
Hi this is embarassing,I still didnt get it despite good advice this is what my code looks like now: <? $to = $_POST['xxxx@xxxxx.com']; $subject = $_POST['Email from website contact form']; $boundary = uniqid(""); $headers = $_POST['from']; $body = " Name :$_POST['user'] Email :$_POST[['emailaddress'] Comment :$_POST['comments'] "; if (mail($to, $subject, $body,$headers)) { print( "Thank you for emailing us.Your file has been sent succesfully"); ?> <meta http-equiv=refresh content="1;URL=http://www.peacefulseasangha.com/files/CUTH.html"> <? } else { print( "Error: Unknown error ocurred. The message could not be sent. Please try again later.\n"); } ?> PHP: sami
<?php $email = $_POST['email']; $message = $_POST['message']; if ($email != "") { if (mail($email, 'test', $message)) echo "Message sent"; else die("Could not send message"); } else { ?><form method="post" action="mail.php"> <input type="text" name="email"> <textarea cols="30" rows="4" name="message"></textarea> <br /><input type="submit" value="Send" name="Send"></form> <?php } ?> Code (markup):