stickynote427 Posted May 16, 2009 Share Posted May 16, 2009 I have a how-to page on my site. To access these how-tos, they are entered in to the URL as GET parameters (...?howto=whatever). I have it set up so that if the how-to does not exist (it is checked from an array), the message, "The how-to you requested does not exist. Feel free to suggest it to us." is echoed. I want "suggest it to us" to be a link (NOT a button) that will execute a PHP mail() somehow. Is there any way I can use a link instead of a button to submit a form using mail()? If not, should I just use CSS styles to style the button to look a bit less like a button? Thanks. Blake Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/ Share on other sites More sharing options...
Masna Posted May 16, 2009 Share Posted May 16, 2009 So, you're trying to use a text link (a element) instead of a form submit button (input element)? <a href="javascript: document.forms[0].submit();">Submit</a> Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835509 Share on other sites More sharing options...
stickynote427 Posted May 16, 2009 Author Share Posted May 16, 2009 Aha! Thank you very much! That should work perfectly! Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835513 Share on other sites More sharing options...
Masna Posted May 16, 2009 Share Posted May 16, 2009 You're welcome. However, beware, some browsers won't respond to that. Do some research and write your own Javascript function that will ensure the form gets submitted in all browsers using that link. Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835515 Share on other sites More sharing options...
stickynote427 Posted May 16, 2009 Author Share Posted May 16, 2009 Alright, thanks. Now I have another problem, though. Will it be possible to set the form's ACTION to $_SERVER['PHP_SELF'] and still use the link? I'm trying to check to see if the form has been submitted by using isset($_POST['submitLink']), but I don't think it's working - because the link is not an input field, its name (submitLink) is not submitted along with the form. Here's the code I have: if ($howtoExists!=1 && !isset($_POST['submitLink'])) { ?> The how-to you requested does not exist. Feel free to <form style="display:inline;" name="howtoSuggestion" method="post" action="<?=$_SERVER['PHP_SELF'];?>?page=how-to&howto=<?=$_GET['howto'];?>"><input type="hidden" name="suggested" value="<?=$_GET['howto'];?>"><a href="javascript:document.forms[0].submit();" name="submitLink">suggest it to us</a></form><br /><br /> <?php } if (isset($_POST['submitLink'])) { mail("myEmailIsHere","How-to Suggestion: ".$_POST['suggested'],"Someone from ".$_SERVER['REMOTE_ADDR']." requested that the following how-to be added to the site: ".$_POST['suggested']); echo "Thank you. Your suggested how-to has been submitted."; } //... Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835523 Share on other sites More sharing options...
Masna Posted May 16, 2009 Share Posted May 16, 2009 Lol, yes, links are not included in $_POST data. Might I suggest a hidden input? <input type="hidden" name="submitLink" value="true"> Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835524 Share on other sites More sharing options...
stickynote427 Posted May 16, 2009 Author Share Posted May 16, 2009 Ah, I never thought of that. It works great! Thank you very much. Link to comment https://forums.phpfreaks.com/topic/158425-solved-sending-email-using-mail-without-a-form/#findComment-835527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.