Benjamin182 Posted January 9, 2009 Share Posted January 9, 2009 I just want to be able to have a php include on my site that allows clients to submit that they want to be added to a monthly email from my company. Just as simple as a text form labled "email" and a submit button that will send their email to me or automatically add them to a mailing list. Any thoughts? Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/ Share on other sites More sharing options...
bubbasheeko Posted January 9, 2009 Share Posted January 9, 2009 That depends, do you already have a database of email addresses? If not then the email approach would be best. Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/#findComment-733613 Share on other sites More sharing options...
Benjamin182 Posted January 9, 2009 Author Share Posted January 9, 2009 That depends, do you already have a database of email addresses? If not then the email approach would be best. I do not have a database of email addresses. How do I create an include that will allow users to send me their email? Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/#findComment-733617 Share on other sites More sharing options...
bubbasheeko Posted January 9, 2009 Share Posted January 9, 2009 Basically you will need to have the html form. As long as this file is a .php file and not an .htm/html file you could add something like this at the top of the page. Assuming you call the html form that has a button called "s1": <? // VARIABLE SETTINGS - LEAVE THESE IN THIS FILE OR IF YOU HAVE A FILE YOU USE FOR SETTINGS THAT IS ALREADY INCLUDED PUT THIS INFORMATION THERE. $myemail = '' // THE EMAIL ADDRESS YOU WANT THE VISITORS EMAIL ADDRESS SENT TO. $subject = '' // WHAT EVER SUBJECT YOU WANT. $message = $_POST['email_address']; // ASSUMING THE TEXT FIELD IN THE FORM IS NAMED 'email_address' // SEND EMAIL ADDRESS if(isset($_POST['s1'])) // CHECKS TO SEE IF THE FORM HAS BEEN SUBMITED { if(mail($myemail, $subject, $message)); // SENDS THE EMAIL { // PUT IN HERE WHAT YOU WANT TO HAPPEN IF THE EMAIL IS SENT SUCCESSFULLY } else { // PUT IN HERE WHAT YOU WANT TO HAPPEN IF THE EMAIL TO YOU FAILS TO SEND } ?> Hope this helps Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/#findComment-733624 Share on other sites More sharing options...
Benjamin182 Posted January 9, 2009 Author Share Posted January 9, 2009 Basically you will need to have the html form. As long as this file is a .php file and not an .htm/html file you could add something like this at the top of the page. Assuming you call the html form that has a button called "s1": <? // VARIABLE SETTINGS - LEAVE THESE IN THIS FILE OR IF YOU HAVE A FILE YOU USE FOR SETTINGS THAT IS ALREADY INCLUDED PUT THIS INFORMATION THERE. $myemail = '' // THE EMAIL ADDRESS YOU WANT THE VISITORS EMAIL ADDRESS SENT TO. $subject = '' // WHAT EVER SUBJECT YOU WANT. $message = $_POST['email_address']; // ASSUMING THE TEXT FIELD IN THE FORM IS NAMED 'email_address' // SEND EMAIL ADDRESS if(isset($_POST['s1'])) // CHECKS TO SEE IF THE FORM HAS BEEN SUBMITED { if(mail($myemail, $subject, $message)); // SENDS THE EMAIL { // PUT IN HERE WHAT YOU WANT TO HAPPEN IF THE EMAIL IS SENT SUCCESSFULLY } else { // PUT IN HERE WHAT YOU WANT TO HAPPEN IF THE EMAIL TO YOU FAILS TO SEND } ?> Hope this helps I understand everything down to the if else statement. I'm a total PHP n00b, and appreciate your patience. When you say "What you want to happen" I understand it would be something like... IF the form is not filled out, then display the form, ELSE the form IS filled out, display a little message that says "Thank you for subscribing to my mailing!" How would I go about doing that in PHP? Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/#findComment-733625 Share on other sites More sharing options...
bubbasheeko Posted January 9, 2009 Share Posted January 9, 2009 if(isset($_POST['s1'])) // CHECKS TO SEE IF THE FORM HAS BEEN SUBMITED { if(mail($myemail, $subject, $message)); // SENDS THE EMAIL { $message = ''// PUT IN HERE WHAT YOU WANT TO SAY IF THE EMAIL IS SENT SUCCESSFULLY } else { $message = ''// PUT IN HERE WHAT YOU WANT TO SAY IF THE EMAIL TO YOU FAILS TO SEND } "email is sent successfully" - you can put something in here to say Thanks.... IE - echo "Thanks!" or create a variable to store a thank you message ($thanks = "Thanks for subscribing" Using echo will put it at the top of the page so people may not be able to see it - not to mention it will use the default font and font color of the page. Thanks for the email address! blah blah blah Your form here blah blah blah Using the echo within the if statement for the email will put your thank you or failure message at the top of the page and may mess up your format of you page. If you use the variable approach you position it just above or below the form. It will trigger using the same trigger as the email being sent: <form action="thispage.php" method="POST"> .... </form> if(isset($_POST['email_address'])) { echo $message; }" I updated the script to show you the variable method. Link to comment https://forums.phpfreaks.com/topic/140191-client-submit-monthly-email-request/#findComment-733637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.