konfused Posted July 28, 2013 Share Posted July 28, 2013 I am familiar with form handlers that send me an email messages from a form, but I now want to do something much less complex but I am not sure how.On my forum, the registered members can post a message to my database, I would like the posting to automatically notify me that a message was sent. This is so that I can quickly moderate the replies and weed out anything offensive. The code for posting a message is as follows: <!doctype html> <html lang=en> <head> <title>The form for posting subjects and messages</title> <meta charset=utf-8> <link rel="stylesheet" type="text/css" href="forum.css"> <style type="text/css"> #tab-navigation ul { margin-left:85px; } form { padding-left:215px; } </style> </head> <body> <div id='container'> <?php // The form for posting messages // Start session session_start() ; // Redirect users if they are not logged in if ( !isset( $_SESSION[ 'member_id' ] ) ) { require ( 'login_functions.php' ) ; load() ; } include ( 'includes/header_post.php' ) ; echo '<h2>Post a Quotation</h2>'; // Display the form fields echo '<form action="process_post.php" method="post" accept-charset="utf-8"> <p>Choose the Subject: <select name="subject"> <option value="Comical Quotes">Comical Quotes</option> <option value="Wise Quotes">Wise Quotes</option> </select></p> <p>Message:<br><textarea name="message" rows="5" cols="50"></textarea></p> <p><input name="submit" type="submit" value="Post"></p></form>'; include ( 'includes/footer.php' ) ; EMAIL MESSAGE TO GO HERE ?> </div> </body> </html> Where I have inserted the line of capital letters, I would like to insert code using mailto() to send me an email message saying "member_id has just posted a message"Also, somehow I need to convert the member_id into a variable.Please would you suggest a sample of email code that I could use. Link to comment Share on other sites More sharing options...
Edward Posted July 29, 2013 Share Posted July 29, 2013 If you were going to do this you would be better of having process_post.php handle the mailto(), you would be able to obtain the member ID in that script from $_SESSION['member_id']. The use the member_id to fetch their username via a simple mysql query and add it to the mailto() function parameter. Otherwise if you don't do it this way and add the mailto() at the bottom of the form script you will find yourself getting emailed everytime someone loads up this form page. Link to comment Share on other sites More sharing options...
konfused Posted July 29, 2013 Author Share Posted July 29, 2013 Thanks Edward Only users who have logged in can click the Add a Message button, and then they can only access this form if they click the "Add a message" button. Please can someone supply the code for emailing myself?. Link to comment Share on other sites More sharing options...
Larry Posted July 29, 2013 Share Posted July 29, 2013 Do you have the book? The book explains how to send an email. Link to comment Share on other sites More sharing options...
konfused Posted July 29, 2013 Author Share Posted July 29, 2013 Yes I have the book and also two others by you. Best manuals I ever bought. I have now found the email details on Page 330, can't understand why I overlooked them. Link to comment Share on other sites More sharing options...
Larry Posted July 29, 2013 Share Posted July 29, 2013 Thanks for the nice words! Link to comment Share on other sites More sharing options...
konfused Posted July 29, 2013 Author Share Posted July 29, 2013 Larry I have re-read pages 330 onwards and I now no why I I overlooked it. It does what I already know, i know how to send information from a form. The code for the form that I posted above is not a form for sending me information in an email. It is form for entering a message into a database table. The emaii I wish to tack on the end, is just to inform me that a message has been posted so that I can moderate it. However, after giving it a little more thought, the form could be a dual purpose form, i.e., it would enter a message in the table and also notify me that a posting had occurred and it could include the message and the username of the person posting the message. So it is up to me to wrestle with the code on pages 330+ so that the post.php code (given above) plus the email, achieve both goals at once.. . Link to comment Share on other sites More sharing options...
Larry Posted July 29, 2013 Share Posted July 29, 2013 Yeah, instead of using form data for what's sent to the mail() function, you'd just use the message data, or whatever else you want. Same idea, just a different application of that idea. Link to comment Share on other sites More sharing options...
Recommended Posts