cheesycarrion Posted May 5, 2007 Share Posted May 5, 2007 the form is at /directory.php?page=mail the script is at /mailsend.php after sent, you're redirected to /directory.php?page=mail_sent, but that's not important. I'm making an email form on my site. the idea is that its main use is when watching a video or something, you click "share" or "send to a friend" or something and it directs you to the form page where you can specify who to send it to, a message and an optional "attachment" (not like an attached file, but a link to a page on the site.) for example, if you click the share link when viewing the numa numa dance, the link will be sent to: /directory.php?page=mail&attachment=media.php?id=numa_numa_dance. Then, on the form, if $_GET["attachment"] is set, creates a hidden input box with its value as the value of $_GET["attachment"] (a link to the numa dance video). otherwise, there is no hidden text box and a link to the homepage is sent. /directory.php?page=mail <form action="mailsend.php" method="post"> <div class="newsarticle"> <div class="newsarticletitle"> Send Email </div> <div class="newsarticlebody"> <span style="width:150px;float:left;"> To: </span> <input type="text" name="to" value="" /><br /> <b>Message Text:</b> <center><textarea name="message" style="width:500px;height:275px;"></textarea></center> <?php if (isset($_GET["attachment"])) { echo "<input type=\"hidden\" disabled=\"disabled\" name=\"attachment\" value=\"" . $_GET["attachment"] . "\" /><br />"; echo "Attachment: <a href=\"/" . $_GET["attachment"] . "\">" . $_GET["attachment"] . "</a><br />"; } ?> <input type="submit" value="send message" /> </div> </div> </form> mailsend.php: <?php include "html/auth.php"; if (isset($_POST["to"]) && isset($_POST["message"])) { if (isset($_POST["to2"])) { if (isset($_POST["to3"])) { if (isset($_POST["to4"])) { $sendto = $_POST["to"] . "," . $_POST["to2"] . "," . $_POST["to3"] . "," . $_POST["to4"]; } else { $sendto = $_POST["to"] . "," . $_POST["to2"] . "," . $_POST["to3"]; } } else { $sendto = $_POST["to"] . "," . $_POST["to2"]; } } else { $sendto = $_POST["to"]; } if (isset($_POST["attachment"])) { $msgattachment = "Attachment: http://www.cheesycarrion.com/" . $_POST["attachment"]; } else { $msgattachment = "www.cheesycarrion.com"; } if ($userdata["session_logged_in"]) { $msgsubject = $userdata["username"] . " has sent you a message at Cheesy Carrion."; $messageass = $userdata["username"] . " has sent you a message at Cheesy Carrion.\n\n" . $_POST["message"] . "\n\n" . $msgattachment; } else { header("Location: account.php?page=login&r=../directory.php?page=mail"); exit; } // send email: mail($sendto,$msgsubject,$messageass); $message = "Message Sent."; header("Location: directory.php?page=mail_sent"); exit; } else { echo "error. not all forms filled out. <a href=\"javascript:history.back(1);\">Go Back.</a>"; } ?> (eventually I'll make a js thing to hide or show other recipients when at the form. that's what all those other "to" things are for. the only problem I've encountered is that even when there's an attachment, you just get a link to www.cheesycarrion.com, which is only supposed to happen if no attachment specified. *userdata array isn't important. it just determines if you're logged in or not, username, etc. update: almost forgot. If you need me to make a test account so you can try it out on my site yourself, leave a reply saying so and I'll private message you the user/pass. Quote Link to comment https://forums.phpfreaks.com/topic/50092-solved-email-form/ Share on other sites More sharing options...
chronister Posted May 5, 2007 Share Posted May 5, 2007 Remove the disabled from the hidden input. Thats what is causing it to not work I copied your code and added the top part to print the Post Array, as soon as I removed the disabled from the hidden input, the post array contained the attachment. <pre> <?php print_r($_POST); ?> </pre> <br /> <br /> <form action="<?=$_SERVER['PHP_SELF'] ?>" method="post"> <div class="newsarticle"> <div class="newsarticletitle"> Send Email </div> <div class="newsarticlebody"> <span style="width:150px;float:left;"> To: </span> <input type="text" name="to" value="" /><br /> <b>Message Text:</b> <center><textarea name="message" style="width:500px;height:275px;"></textarea></center> <?php if (isset($_GET["attachment"])) { // REMOVE DISABLED FROM THE LINE BELOW // echo "<input type=\"hidden\" name=\"attachment\" value=\"" . $_GET["attachment"] . "\" /><br />"; echo "Attachment: <a href=\"/" . $_GET["attachment"] . "\">" . $_GET["attachment"] . "</a><br />"; } ?> <input type="submit" value="send message" /> </div> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/50092-solved-email-form/#findComment-245951 Share on other sites More sharing options...
cheesycarrion Posted May 5, 2007 Author Share Posted May 5, 2007 thanks. now that I think about it, "disabled" isn't even needed since its hidden anyway. Quote Link to comment https://forums.phpfreaks.com/topic/50092-solved-email-form/#findComment-245991 Share on other sites More sharing options...
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.