pedrwvargas Posted May 9, 2017 Share Posted May 9, 2017 It just doesn't work. It does work if I keep it simple with no html involved. What am I doing wrong? Are all those divs inside the form a problem? Thanks! *myemail@gmail.com is changed for my real email in the code so that is not the problem. <section> <h2>get in touch</h2> <?php if (isset($_REQUEST['email'])) { $admin_email = 'myemail@gmail.com'; $email = $_REQUEST['email']; $name = $_REQUEST['name']; $message = $_REQUEST['message']; mail($admin_email, '$name', $message, 'From:' . $email); echo '<p>your message has been sent and we will reply as soon as possible <br>thanks for being patient</p>'; } else { ?> <form method="post"> <div class="field half first"> <input type="text" name="name" id="name" placeholder="name" /> </div> <div class="field half"> <input type="email" name="email" id="email" placeholder="email" /> </div> <div class="field"> <textarea name="message" id="message" rows="4" placeholder="message"></textarea> </div> <ul class="actions"> <li><input type="submit" value="send" class="special" /></li> <li><input type="reset" value="reset" /></li> </ul> </form> <?php } ?> </section> Quote Link to comment Share on other sites More sharing options...
maxxd Posted May 9, 2017 Share Posted May 9, 2017 You're going to have to describe the problem more fully than "It just doesn't work". I'm assuming there's no error being displayed as you've got no error checking set up. What doesn't work? The form doesn't display, the mail doesn't send, your cat stops talking to you? Please be more specific and we can try to help you. In the meantime, your script is a veritable playground for script kiddies who want to spam the crap out of everyone everywhere. A user doesn't even have to actually submit your form to send emails. And by simply assuming the from email is actually that, you're opening yourself up to letting a malicious user carbon copy, blind carbon copy, and send directly to anyone he or she wants. Quote Link to comment Share on other sites More sharing options...
pedrwvargas Posted May 9, 2017 Author Share Posted May 9, 2017 You're going to have to describe the problem more fully than "It just doesn't work". I'm assuming there's no error being displayed as you've got no error checking set up. What doesn't work? The form doesn't display, the mail doesn't send, your cat stops talking to you? Please be more specific and we can try to help you. In the meantime, your script is a veritable playground for script kiddies who want to spam the crap out of everyone everywhere. A user doesn't even have to actually submit your form to send emails. And by simply assuming the from email is actually that, you're opening yourself up to letting a malicious user carbon copy, blind carbon copy, and send directly to anyone he or she wants. Both the mail doesn't send and my cat stopped talking to me. I already fixed the cat problem but can't figure out what's wrong with the code other than being for script kiddies who want to spam the crap out of everyone all over the planet Earth and beyond. Now, seriously no error has been displayed so apparently there's no error (but there is lol). I'll try to be more specific next time, sorry about that. Quote Link to comment Share on other sites More sharing options...
Solution maxxd Posted May 9, 2017 Solution Share Posted May 9, 2017 OK - is anything being displayed? Add <?php error_reporting(E_ALL); ini_set('display_errors', true); ?> to the very top of your script. Do you get an error before you try to submit the form? Or after? Just looking at it, it could be that you're trying to send an email to the literal string '$name' - single quotes in PHP don't allow variable parsing. Plus, they're not necessary in this instance. And all joking aside, please do check into some validation before you use the mail() function. You'll be glad for it later. Quote Link to comment Share on other sites More sharing options...
pedrwvargas Posted May 9, 2017 Author Share Posted May 9, 2017 OK - is anything being displayed? Add <?php error_reporting(E_ALL); ini_set('display_errors', true); ?> to the very top of your script. Do you get an error before you try to submit the form? Or after? Just looking at it, it could be that you're trying to send an email to the literal string '$name' - single quotes in PHP don't allow variable parsing. Plus, they're not necessary in this instance. And all joking aside, please do check into some validation before you use the mail() function. You'll be glad for it later. Problem solved! It had to do with the single quotes. Thank you very much. As for validation I'll have a look and try to apply it to my code. Quote Link to comment Share on other sites More sharing options...
maxxd Posted May 10, 2017 Share Posted May 10, 2017 Problem solved! It had to do with the single quotes. Thank you very much. As for validation I'll have a look and try to apply it to my code. Please do, and while you're at it you'll want to look at error checking. Together, they'll save you many headaches in the long run. As far as mail-specific things go, in the future you may want to look into PHPMailer - it's safer, more robust, and more reliable than the built-in PHP mail() function. Also, glad the cat's talking to you again. Quote Link to comment 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.