martinstan Posted January 12, 2007 Share Posted January 12, 2007 HiSorry for a painfully basic question but I'm having problems with this form. It kind of works but instead of the information collected in the fields being in the body of the email, it's appearing as the mail subject???Please help!ThanksMartin[code]<?php$to = "info@myemailaddress.co.uk";$name = $_POST['name'];$tel = $_POST['tel'];$email = $_POST['email'];$msg = $_POST['msg'];$d = date('l dS \of F Y h:i:s A');$sub = "Contact from website";$headers = "From:" .$name .$email."\n"; $mes .= "Message: ".$msg."\n";$mes .= "Name: ".$name."\n";$mes .= "Tel: ".$tel."\n";$mes .= 'Email: '.$email."\n";$mes .= 'Date & Time: '.$d;if (empty($name) || empty($tel) || empty($email) || empty($msg)){ echo " <h3>Sorry all fields are required.</h3>";}elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { print " <h3>Sorry the email address you entered looks like it's invalid.</h3>";}else{ mail($to, $mes, $headers); print " <h3><center>Thank you ".$name." for contacting us.<br>We will get back to you as soon as possible</center></h3>"; }?>[/code]the form[code] <form method="post" action="send.php"> Name:<br><input name="name" type="text" size="40"> <br><br> Tel:<br><input name="tel" type="text" size="40"> <br><br> Email:<br><input name="email" type="text" size="40"> <br><br> Message:<br><textarea name="msg" cols="40" rows="6"></textarea> <br><br> <input type="reset" value="Reset"> <input type="submit" value="Send"> </form>[/code] Quote Link to comment Share on other sites More sharing options...
Cep Posted January 12, 2007 Share Posted January 12, 2007 Try this,[code=php:0]$mes = "Message: ".$msg."\n";$mes .= "Name: ".$name."\n";$mes .= "Tel: ".$tel."\n";$mes .= 'Email: '.$email."\n";$mes .= 'Date & Time: '.$d;[/code]Also remember your mail function should be$mail = mail($to, $subject, $message, $headers); Quote Link to comment Share on other sites More sharing options...
martinstan Posted January 12, 2007 Author Share Posted January 12, 2007 Hi CepThanks for your help but now I'm getting an email with an empty body, no subject, however it does say who it is from.Do I need to create the '$mail' variable anywhere?Martin Quote Link to comment Share on other sites More sharing options...
martinstan Posted January 12, 2007 Author Share Posted January 12, 2007 Hi CepSorry, I cut and pasted what you put and then realised you'd put '$message' instead of '$mes'. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.