andrew_biggart Posted October 5, 2010 Share Posted October 5, 2010 Ok what I am trying to do it make a simple form. Once the user has eneter all the details and clicked submit I want this information to be sent to me in an email. So far I have got the email sending but i am just having trouble getting the information to be displayed correctly in the email that is sent. For the subject I want first name last name <email>. And then for the main message of the email I want the information from the form to displayed something like the following. First Name : '$fname' Last Name : '$lname' and so on for all the variables i have collected from the online form. Here is what I have got so far and I would appreciate any help you can give me thanks. <?php if ($_SERVER['REQUEST_METHOD']=="POST"){ // Recipent Email $to="andrew@peppermintdigital.com"; $subject="Reply to Peppermint Invitation"; $title = $_POST['title']; $fname = stripslashes($_POST['fname']); $sname = stripslashes($_POST['sname']); $add1 = stripslashes($_POST['add1']); $add2 = stripslashes($_POST['add2']); $add3 = stripslashes($_POST['add3']); $add4 = stripslashes($_POST['add4']); $postcode = stripslashes($_POST['postcode']); $number = stripslashes($_POST['number']); $email = stripslashes($_POST['email']); $time = $_POST['time']; $from = stripslashes($_POST['fname']) ."<".stripslashes($_POST['email']).">"; // Email Message $message = $_POST['postcode']; $body = "hello"; // Validation Begins // Add Erros To Array $errors = array(); // Check Form if (!$_POST['title']) $errors[] = "Title Required"; if (!$_POST['fname']) $errors[] = "Forename Required"; if (!$_POST['sname']) $errors[] = "Surnname Required"; if (!$_POST['add1']) $errors[] = "Address Required"; if (!$_POST['add4']) $errors[] = "City Required"; if (!$_POST['postcode']) $errors[] = "Postcode Required"; if (!$_POST['number']) $errors[] = "Number Required"; if (!$_POST['email']) $errors[] = "Email Required"; if (!$_POST['time']) $errors[] = "Time Required"; // Display Errors if (count($errors)>0) { echo"<h1 class='fail'>"; foreach($errors as $err) echo "$err.\n"; echo"</h1>"; } else { // Build message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // Build message body // Insert two dashes in front of the MIME boundary when we use it $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Start of attachment $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // Send message if (@mail($to, $subject, $message, $headers)) echo "<h1 class='success'>Your message has been sent.</h1>"; else echo "<h1 class='fail'>Your message was not sent at this time.</h1>"; } } else { } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 you need to append that information to $subject which is the subject of the email, and $message which is the content you are sending. are you actually attaching a file? if not, i'd skip the mime stuff. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted October 5, 2010 Author Share Posted October 5, 2010 I have got it working but i cannot get each individual variable on seperate lines and line breaks dont wotk. How would I do it? I have got at the moment // Email Message $message = "Name : $title $name. Address : $add1, $add2, $add3, $add4, $postcode. Phone Number : $number. Email : $email. Appointment Time : $time"; But I want it displayed like this. Name : $name Address : $add1 $add2 etc etc Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 what do you mean line breaks don't work? it might be your email application. you might need \r\n instead of just \n. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted October 5, 2010 Author Share Posted October 5, 2010 I dotn know what you mean? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 in some cases, you may need to insert the code for a line break, either \n or (for some Windows users) \r\n, like so: $message = "Name : $title $name.\n Address : $add1, $add2, $add3, $add4, $postcode.\n Phone Number : $number.\n Email : $email.\n Appointment Time : $time\n"; 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.