.Jay Posted January 24, 2007 Share Posted January 24, 2007 Hi all,I run a gaming clan website for roughly 75 members. As you can understand it can be time consuming retrieving their E-Mail address to send them a standard E-Mail, especially when you've got a lot of members to E-Mail.What I've been doing over the past few weeks I've started to learn PHP (I've never used it before you see). I'm in the process of making a member manager whereby you can change their access rights on the website, delete them, change their member status (when they become full members etc) and I'm also looking at adding a email function. This is the main bit I'm having trouble with.At the moment we have 4 standard E-Mails (Welcome, Promotion, Suspension and Termination). These at the moment have to be sent by hand by an admin to the person in question. I'm looking at making this easier by having the emails sorted somewhere (in a MySQL database maybe?) and having a button on the member manager to E-Mail a specific person with a specific E-Mail. I already know how to pull their E-Mail address and Name from the member database, I just don't have a clue about getting the E-Mails working.The layout is basic at the moment and is done in a table (Screenshot here [url=http://www.ctclan.co.uk/user/membermanager.jpg]http://www.ctclan.co.uk/user/membermanager.jpg[/url]). The idea I had was adding an extra column with a drop down menu for each member with the different E-Mails that can be sent. When an email is chosen a send button is clicked and its all done.Is there anyone that can help with this at all, or just pointing me in the right direction would be a great help!Thanks,.Jay Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/ Share on other sites More sharing options...
Psycho Posted January 24, 2007 Share Posted January 24, 2007 Well, I would do the following:Create a "processing" page for those email links (I'll get to the specifics later). Then for each of those links have them point to the processing page and append the type of email and the user email on the query string. Something like this:href="memberemail.php?etype=promote&[email protected]"Now on the processing page, since you only have four emails I would suggest just keeping the email text within the processing page itself instead of putting it in the database. Putting it in the database, however, would be usefull if other people will need to edit the standard text - although I'll show a way to let any admin modify each email text on an individual basis.Ok, so now for the processing page. I'll let you worry about the "framework" of the page (i.e. header, footer, styles etc.), but here is the basics I would use for creating the processing page:[code]if (!isset($_GET['etype']) && isset($_GET['useremail'])) { echo "No email type or user email set.";} else { switch ($_GET['etype']) { case "Welcome": $subject = "Welcome to the clan." $message = "You are now a member."; break; case "Promotion": $subject = "You've been promoted." $message = "Congratulations, you are a full member."; break; case "Suspension": $subject = "You've been suspended." $message = "Stop being a smacktard."; break; case "Termination": $subject = "You've been terminated." $message = "Go away and die, scum."; break; } if (!$msg) { echo "Invalid email type."; } else { $adminemail = "[email protected]"; $headers = "From: $adminemail\r\n" . "Reply-To: $adminemail\r\n" . "X-Mailer: PHP/" . phpversion(); if(mail($_GET['useremail'], $subject, $message, $headers)) { echo "Email successfully sent."; } else { echo "There was a problem sending the following email:<br><br> } }}[/code]Now, another option which will allow customization of the messages would be to have the values for the email populate form fields instead of actually sending the email. Then add a switch on the page to test for POST data and send the email based on that. Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/#findComment-168148 Share on other sites More sharing options...
.Jay Posted January 24, 2007 Author Share Posted January 24, 2007 That's a great great help! Thanks!You mentioned being able to customize the message. That would be useful to change members details etc as each E-Mail could do with slight alterations. What would be the easiest way to go about it? I understand what you have written so it should be quite good to implement it. One question is that the E-Mails we send are fairly large, are there any restrictions or is it just a copy and paste job between the quotation marks (adding html formatting i suppose?).Thanks,.Jay Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/#findComment-168170 Share on other sites More sharing options...
Psycho Posted January 24, 2007 Share Posted January 24, 2007 Just copy and paste your content for the messages into the appropriate variables.To be able to customize the emails before sending, just do something like I mentioned above and put the data into a form first. Something like I have below. I'm sure there are some typos and possibly other errors as I have not tested it. Let me know if you can't get it working.Edit: removed code. See next post Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/#findComment-168298 Share on other sites More sharing options...
Psycho Posted January 24, 2007 Share Posted January 24, 2007 OK, I went and tested it and cleaned up some of the errors. try this:[code]<html><head></head><body><?phpif (isset($_POST['submit'])) { //You could add more validations here if ($_POST['email']=="" || $_POST['subject']=="" || $_POST['message']=="") { $error = 'Some fields are blank.'; } $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $sendemail = true;} else { if (!isset($_GET['etype']) || !isset($_GET['useremail'])) { $error = 'Email type or user email not set.'; } else { $email = $_GET['useremail']; switch ($_GET['etype']) { case "Welcome": $subject = "Welcome to the clan."; $message = "You are now a member."; break; case "Promotion": $subject = "You've been promoted."; $message = "Congratulations, you are a full member."; break; case "Suspension": $subject = "You've been suspended."; $message = "Stop being a smacktard."; break; case "Termination": $subject = "You've been terminated."; $message = "Go away and die, scum."; break; } if (!$message) { $error = 'Invalid email type set.'; } }}if ($sendemail && !$error) { $adminemail = '[email protected]'; $headers = "From: $adminemail\r\n" . "Reply-To: $adminemail\r\n" . "X-Mailer: PHP/" . phpversion(); if(mail($_GET['useremail'], $subject, $message, $headers)) { echo 'Email successfully sent.'; } else { echo 'There was a problem sending the following email:<br><br>'; }} else { if ($error) { echo 'Error: ' . $error; } echo "<br><br><form name=\"sendemail\" action=\"{$PHP_SELF}\" method=\"POST\">\n" . "Email: <input type=\"text\" name=\"email\" value=\"{$email}\" /><br>\n" . "Subject: <input type=\"text\" name=\"subject\" value=\"{$subject}\" /><br>\n" . "Message: <textarea name=\"message\">{$message}</textarea><br>\n" . "<button type=\"submit\" name=\"submit\" value=\"Send Email\">Send the email</button>";}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/#findComment-168307 Share on other sites More sharing options...
.Jay Posted January 27, 2007 Author Share Posted January 27, 2007 Sorry for the late reply! I've been at work the last 3 days covering shifts :-\Anyway, that worked great mate, thank you so much for your time and effort with the coding. Its helped me a lot as well as improved my understanding of PHP as a whole.Thanks! Link to comment https://forums.phpfreaks.com/topic/35516-solved-sending-predefined-e-mails/#findComment-170744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.