Faliol Posted January 8, 2004 Posted January 8, 2004 Hi I'm working on a form where when the user hits the submit button it submits the info to my email address so i can access their info. I created the php and form code but do not know how to make send email to me when it submits. Can anyone help? I think it has something to do with the mail () function or phi.ini, but not sure. I do not see the php.ini Here's the page in question http://www.eberotic.com/contact.php And here's the PHP and html source code: Thanks in advance ><?php $page_title = 'EB Erotic | Contact'; include ('templates/header.inc'); ?> <h1>Contact</h1> </div> <div class="Article"> <div id="top-cap"><img src="/images/top_cap.gif" alt="" /></div> <div id="wrapper"> <div id="menu"> <?php include ('templates/navigation.inc'); ?> </div> <div id="content"> <?php if (isset($_POST['submit'])) { // Handle the form. // Check for a name. if (strlen($_POST['name']) > 0) { $name = TRUE; } else { $name = FALSE; echo '<p>You forgot to enter your name!</p>'; } // Check for an email address. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; echo '<p>You forgot to enter your email address!</p>'; } // Check for a username. if (strlen($_POST['subject']) > 0) { $subject = TRUE; } else { $subject = FALSE; echo '<p>You forgot to enter your user name!</p>'; } // Check for a username. if (strlen($_POST['comments']) > 0) { $comments = TRUE; } else { $comments = FALSE; echo '<p>You forgot to enter your comments!</p>'; } if ($name && $email && $subject && $comments) { // If everything's okay. // Register the user. echo '<p>Thanks You for your email. I will reply as soon as possible.</p>'; } else { // Something's not TRUE. echo '<p>Please go back and try again.</p>'; } } else { // Display the form. ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <legend>Enter your information in the form below:</legend> <p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="25" maxlength="60" /> </p> <p><b>Subject:</b> <input type="text" name="subject" size="20" maxlength="40" /></p> <p><b>Comments:</b> <textarea name="comments" cols="60" rows="10"></textarea> </p> <div align="center"><input type="submit" name="submit" value="Submit Information" /></div> </form><!-- End of Form --> <?php } // End of mian Submit conditional. ?></div> <div style="clear: both;"> </div> <div id="bootom_cap"><img src="/images/bottom_cap.gif" /></div> </div> </div> <?php include ('templates/footer.inc'); // Include the HTML footer. ?> Quote
Frylock Posted January 8, 2004 Posted January 8, 2004 Do you mean just the PHP function that does this? Like... >$youremail = "youremail@******"; $subjectline = "New Comments from $name"; $letter = "User $subject sent you these comments:\n\n$comments"; $headers = "From: $name <$email>\n"; mail($youremail, $subjectline, $letter, $headers); Quote
Faliol Posted January 8, 2004 Author Posted January 8, 2004 yes that's what I mean but I do not know how to implement it in the specific code I have. Where would I put it? thaks your the help Quote
Faliol Posted January 8, 2004 Author Posted January 8, 2004 Basically I need to get email with the info the user submitted when they hit the submit button. How would I implement that into my code? Im fairly new at PHP so Im at a lost. Quote
glassgorilla Posted January 8, 2004 Posted January 8, 2004 >if ($name && $email && $subject && $comments) { // If everything's okay. // Register the user. echo '<p>Thanks You for your email. I will reply as soon as possible.</p>'; } else { // Something's not TRUE. echo '<p>Please go back and try again.</p>'; } where it says //Register the user is where it was successful. so i'm assuming it would go there. >if ($name && $email && $subject && $comments) { // If everything's okay. // Register the user. $youremail = "youremail@******"; $subjectline = "New Comments from $name"; $letter = "User $subject sent you these comments:\n\n$comments"; $headers = "From: $name <$email>\n"; if(mail($youremail, $subjectline, $letter, $headers)){ echo '<p>Thanks You for your email. I will reply as soon as possible.</p>'; } else { echo '<p>There was an error sending the email.</p>'; } } else { // Something's not TRUE. echo '<p>Please go back and try again.</p>'; } Quote
Faliol Posted January 8, 2004 Author Posted January 8, 2004 Thanks man, it's almost there. I'm getting the email now, but the contents are not showing right. I added this to where you said I should add it: $youremail = "kevin@lectric.com"; $subject = "New Comments from $name"; $comments = "$name sent you these comments:\n\n$comments"; $headers = "From: †$name <$email>\n"; mail($youremail, $subject, $comments, $headers); The email I got is like this Email came from 1 <1@server45.totalchoicehosting.com> Subject: New Comments from 1 and the body of the email is : 1 sent you these comments: 1 I entered Test in every field except I entered my email in the email field. Know the problem of why it's doing this? Quote
glassgorilla Posted January 9, 2004 Posted January 9, 2004 the problem is not with the email part. if you echo the variables to the page, you will see this: >Thanks You for your email. I will reply as soon as possible. kevin@lectric.com, New Comments from 1, User 1 sent you these comments: 1, From: 1 <1> i'm still looking at the code to see why everything would be a 1. Quote
glassgorilla Posted January 9, 2004 Posted January 9, 2004 oh, i see. when it checks to make sure all the fields are filled in, it sets them to true. true is the same thing as '1'. the "youremail" variable is not sent through the form, never checked and set to true or false, which is why it was sending you mail instead of mail to the email address "1" so for example: >if (strlen($_POST['name']) > 0) { $name = TRUE; } else { $name = FALSE; echo '<p>You forgot to enter your name!</p>'; } this sets "$name" to true (1), which why in your email, "$name" appears as one. you will just have to use different variables at the beginning. put these four lines under the if(isset(etc...) // handle the form line. >if (isset($_POST['submit'])) { // Handle the form. $name2 = $_POST['name']; $email2 = $_POST['email']; $subject2 = $_POST['subject']; $comments2 = $_POST['comments']; and then change your mail code to this: >if ($name && $email && $subject && $comments) { // If everything's okay. // Register the user. $youremail = "kevin@lectric.com"; $subjectline = "New Comments from $name2"; $letter = "User $name2 sent you these comments:\n\n$subject2\n\n$comments2"; $headers = "From: $name2 <$email2>\n"; if(mail($youremail, $subjectline, $letter, $headers)){ echo '<p>Thanks You for your email. I will reply as soon as possible.</p>'; } else { echo '<p>There was an error sending the email.</p>'; } } else { // Something's not TRUE. echo '<p>Please go back and try again.</p>'; } Quote
Frylock Posted January 9, 2004 Posted January 9, 2004 Whoops, yeah I misread what your variables were set to. Do what that glassgorilla says instead. Quote
Faliol Posted January 12, 2004 Author Posted January 12, 2004 Thanks guys Glassgorilla, I pasted your code in but I'm getting a parse error at line 45. You know the problem? ><?php $page_title = 'EB Erotic | Contact'; include ('templates/header.inc'); ?> <h1>Contact</h1> </div> <div class="Article"> <div id="top-cap"><img src="/images/top_cap.gif" alt="" /></div> <div id="wrapper"> <div id="menu"> <?php include ('templates/navigation.inc'); ?> </div> <div id="content"> <?php if (isset($_POST['submit'])) { // Handle the form. $name2 = $_POST['name']; $email2 = $_POST['email']; $subject2 = $_POST['subject']; $comments2 = $_POST['comments']; // Check for a name. if (strlen($_POST['name']) > 0) { $name = TRUE; } else { $name = FALSE; echo '<p>You forgot to enter your name!</p>'; } // Check for an email address. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; echo '<p>You forgot to enter your email address!</p>'; } // Check for a username. if (strlen($_POST['subject']) > 0) { $subject = TRUE; } else { $subject = FALSE; echo '<p>You forgot to enter your user name!</p>'; } // Check for a username. if (strlen($_POST['comments']) > 0) { $comments = TRUE; } else { $comments = FALSE; echo '<p>You forgot to enter your comments!</p>'; } if ($name && $email && $subject && $comments) { // If everything's okay. // Register the user. $youremail = "kevin@lectric.com"; $subjectline = "New Comments from $name2"; $letter = "User $name2 sent you these comments:\n\n$subject2\n\n$comments2"; $headers = "From: $name2 <$email2>\n"; if(mail($youremail, $subjectline, $letter, $headers)){ echo '<p>Thanks You for your email. I will reply as soon as possible.</p>'; } else { echo '<p>There was an error sending the email.</p>'; } } else { // Something's not TRUE. echo '<p>Please go back and try again.</p>'; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <legend>Enter your information in the form below:</legend> <p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="25" maxlength="60" /> </p> <p><b>Subject:</b> <input type="text" name="subject" size="20" maxlength="40" /></p> <p><b>Comments:</b> <textarea name="comments" cols="60" rows="10"></textarea> </p> <div align="center"><input type="submit" name="submit" value="Submit Information" /></div> </form><!-- End of Form --> <?php } // End of mian Submit conditional. ?></div> <div style="clear: both;"> </div> <div id="bootom_cap"><img src="/images/bottom_cap.gif" /></div> </div> </div> <?php include ('templates/footer.inc'); // Include the HTML footer. ?> Quote
TCH-Rob Posted January 12, 2004 Posted January 12, 2004 Watch when pasting code that you dont have any spaces after your ;'s. I show line 45 as $email = FALSE; Check to see that there are no spaces after it, press your delete key until the word "echo" is next to the ";" and then press the enter key once. The code looks fine to me, I am a novice though so thats all I can think of. Try that while we wait for a PHP pro. Quote
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.