Can anyone explain how, with PHP, I can provide the option for visitors to e-mail my content to friends? For example: Next to my content, I'll have an e-mail buttom. When visitors click it, an e-mail window will open, pre-populated with my content (selected from a database). All the visitor has to do is enter an e-mail address, hit "Submit" and send my content to a friend. Anyone know how to do it?
My content is dynamic. I SELECT it from a MySQL database, and echo it in a WHILE loop. It's a list of jokes, each one with its own ID. What I want to do is, have an "E-mail this Joke to a Friend" link under each joke. When clicked, I want an e-mail box to open with the joke inside. I want it so that all the visitor has to do is input the e-mail address and hit "Send". I know how to SELECT the jokes, but I don't understand how to do the rest. Will the button be an <INPUT> tag? During the initial WHILE loop which echos the jokes onto my page, do I call the IDs and have them echoed into the NAME attribute of each joke's <INPUT> tag? Do I then $_POST the ID to another page which SELECTs the joke and puts it into an e-mail form? ANyone know?
I'd say the best way would be to have an email form on a separate page, and to send the id to that page, so sendform.php is the form Then in your jokes output, have a link to sendform.php?id=X where x is the joke id Then when the user clicks on that link, it shows the page, with a box for the email address of the recipient and a box for the sender name (optionally their email too). You DO NOT want to allow the joke to be editable since that is a prime example of how spammers can abuse your system. just have a hidden field with the joke id and retrieve the joke before sending the email
Thanks, Jay! Rep points added! A quick question . . . I echo my jokes onto my page in a while loop. How do I put the while loop results into a variable to send to the next page, which will e-mail the joke?
OK. Beneath each joke (in fact, they're coupons!), I have this form: <form action=\"email-coupon.php?id=" . $row['id'] ."\" method=\"post\"> <input type=\"image\" src=\"images/emailcpn.png\" /> </form> Code (markup): It sends the ID of the coupon to email-coupons.php. Email-coupons.php selects the coupon based on the ID and echos it like this: while($row = mysql_fetch_assoc($query)) { echo "<form action=\"email-coupons-manager.php\" method=\"post\">"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "Coupon: <a href=\"" . $row['bmurl'] . "\">" . $row['anch'] . "</a><br />"; echo "Store: " . $row['adv']; echo "<br /> Expires: "; echo (empty($row['formated_date']) ? $row['expun'] : $row['formated_date']); echo "<br /> Instructions: "; echo (empty($row['code']) ? $row['instr'] : $row['code']); echo "<br />If the link above doesn't work, copy and paste the link below into address bar:<br />"; echo $row['bmurl']; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "Additional words (optional):<br />"; echo "<textarea name=\"message\" rows=\"5\" cols=\"35\"></textarea>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "Send to (e.g., john@aol.com, sarah@yahoo.com):<br />"; echo "<textarea name=\"to\" rows=\"1\" cols=\"35\"></textarea>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "From (your e-mail address):<br />"; echo "<textarea name=\"from\" rows=\"1\" cols=\"35\"></textarea>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<br /><input type=\"submit\" name=\"send\" value=\"Send\" />"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; } PHP: As you can see, on email-coupons-manager.php, I can collect the to and from, but not the coupon itself. I need to be able to send the coupon to email-coupons-manager.php in a variable. Do you know how I can do this?
In that form, have a hidden input with the coupon id <input type="hidden" name="couponid" id="couponid" value="COUPONIDHERE" /> HTML:
OK. But then I'll have to SELECT the coupon again on the email-coupons-manager.php page. Although that's fine, I will still have to put the coupon into a variable before I can e-mail it: $to = $_REQUEST['to']; $from = $_REQUEST['from']; $message = $_REQUEST['message']; mail($to, $from, $message, $coupon); PHP: How can I put the coupon into a variable so I can send it with the $to and $from?
run your query for the id, get the coupon and append/prepend it to your $message contents you need to do it this way to make sure your coupon gets sent to the user, otherwise the person can edit out the coupon You should really be checking the fields for spam preventing, in case someone has a list of email addresses and just spam. Another thing you should be using is $_POST rather than $_REQUEST
Sorry I misread... $query = sprintf("SELECT * FROM `coupon_table_name` WHERE `id`='%d'",$_POST['couponid']); $res = mysql_query($query); if(!$res) { //ERROR STUFF HERE }else{ $row = mysql_fetch_assoc($res); $coupon = $row['coupon_column_name']; //EMAIL HERE } PHP: