jonyork Posted March 31, 2007 Share Posted March 31, 2007 hey guysim new at php, and im trying to make a sendmail form. now ive got the sendmail working like this<?php$to = "info@somedomain.com";$subject = "Test mail";$message = "Hello! This is a simple email message.";$from = "Maintenance";$headers = "From: $from";mail($to,$subject,$message,$headers);echo "Mail Sent.";?>now the thing is, my form looks like this <form action="php.php" method="post">First name: <input type="text" name="firstname" /><br />Last name: <input type="text" name="lastname" /><br />Phone Number: <input type="text" name="year" /><br />Email : <input type="text" name="make" /><br />Model: <input type="text" name="model" /><br />Engine: <input type="text" name="engine" /><br /><br />Special Details: <textarea name="problem" cols="75" rows="4"></textarea><br /><br /><input type="submit" /></form>now how do i send all that info with the $message variable? or is there a much easier/better way that im overlooking? any help would be aprreciatedJon York Link to comment Share on other sites More sharing options...
jlhaslip Posted April 1, 2007 Share Posted April 1, 2007 Instead of defining the message as : $message = "Hello! This is a simple email message."; you need to pick up the data in the $_POST array and include them in the message variable you have named "$message". One way to do that is to have the signifigant data items added to the message as follows: $message = $_POST['firstname'] . "\n\r";$message .= $_POST['lastname'] . "\n\r;and so one ... for each 'named' element from your form... Notice the 'period' in front of the equal sign? That is the concatenation operator. It causes each value of the $_POST[] to be 'concatenated' to the $message and the '\n\r' adds a new line/carriage return to the line of the message so it becomes readable to the user receiving it. Alternately, you might want to create a loop of length = the count of the $_POST[] elements and concatenate the parts into the message using a similar technique.I haven't tested the code, so if there is an error, someone will advise. And it has been awhile since I have written a mail script, but that is the way I would do it. This code belongs in the file you declare as the 'action=' for the form, in place of the code you have posted or the message contents. Link to comment Share on other sites More sharing options...
jonyork Posted April 1, 2007 Author Share Posted April 1, 2007 thanks bud, that works just perfectly. one ticker however. on my emaisl the info comes back like thisfirstnamelastnamephoneemaildetailsmy php script looks like this <?php$to = "info@yorkdigitalsolutions.com";$subject = "Test mail";$message = $_POST['firstname'] . "\n\r";$message .= $_POST['lastname'] . "\n\r";$message .= $_POST['phone'] . "\n\r";$message .= $_POST['email'] . "\n\r";$message .= $_POST['details'] . "\n\r";$from = "Maintenance";$headers = "From: $from";mail($to,$subject,$message,$headers);echo "<h3>Information Submitted</h3>";?>id like for there to be a line between email and details if possiblethanks Link to comment Share on other sites More sharing options...
jlhaslip Posted April 1, 2007 Share Posted April 1, 2007 Try this:$message .= $_POST['email'] . "\n\r\n\r"; Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2007 Share Posted April 2, 2007 Actually, it's better to use only \n for email bodies. Nothing really uses \n\r, but \r\n is used to separate the headers in an email. Simply \n should be used for linebreaks inside the body itself. Link to comment Share on other sites More sharing options...
msd Posted April 8, 2007 Share Posted April 8, 2007 And the headers should be more specific: $headers = "MIME-Version: 1.0\r\n";$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";$headers .= "From: $from"; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now