Chrisj Posted August 1, 2018 Share Posted August 1, 2018 (edited) The contact Form mails successfully to the $youremail part of this code, but I'd like the message to also mail to the submitter's entered email address, which I believe is: E-Mail: $_POST I tried this without success: <?php // if the url field is empty //if(isset($_POST['url']) && $_POST['url'] == '') { $youremail = 'wcform@....com'; $body = "UploadForm-M: Name: $_POST[name] E-Mail: $_POST[email] Message: $_POST[message]"; if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) { $headers = "From: $_POST[email]"; $headers = "From: $youremail"; } mail($youremail, 'Contact Form', $body, $headers ); mail(email, 'Contact Form', $body, $headers ); } if(empty($error)) { header('Location: http://...com'); exit; } ?> Any additional help will be appreciated. Edited August 1, 2018 by Chrisj Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2018 Share Posted August 1, 2018 Okay. So you know the email is $_POST["email"]. How about fixing the code so it, you know, actually uses that? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2018 Share Posted August 1, 2018 Ok - so do you see what's wrong with this line? mail(email, 'Contact Form', $body, $headers ); } The word "email". What is that actually? If you had error checking turned on you probably would be seeing a message. Actually, I'm surprised the script even runs with that in it. (Must be defaulting to a constant that is not defined.) You need a variable there or an actual string (text in quotes). The better way might be to add your second address to the headers as a CC: which you could look up in the PHP manual. That way you just have one email going out. (Or a BCC if you want to hide it) Quote Link to comment Share on other sites More sharing options...
Chrisj Posted August 1, 2018 Author Share Posted August 1, 2018 Thanks for your replies. Can you give me an example of what you're describing? Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2018 Share Posted August 1, 2018 I'll be honest with you: this is not the sort of thing that should need an example. ginerjm pointed out the line of code that needs fixing, and that the "email" bit is what's wrong. You already know that the email address you want is in $_POST (not literally $_POST but one of the values in it). So it should just be a matter of taking the bad thing out and putting the good thing in. That should get you something that at least works correctly, however it may have a subtle flaw to it so I suggest posting what you end up with just in case. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2018 Share Posted August 1, 2018 As Requinex says - make some changes and try it out and then show us what is failing. I, for one, am not sure what kind of example you need since I only posted one line of your code and pointed out its weakness. BTW - while it is allowed and does in fact work (although at an extra expense I'm sure) PHP will work more efficiently if you wrap your array indices in quotes. An example of that is simply: $array['index'] 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.