fatboymills Posted May 5, 2014 Share Posted May 5, 2014 Ok, how about this one... I want to send the contents of my form back to the users email as well as mine. My Email is written at the top of the code to send the form to, but I want him to get the same copy of the email. I have the variable $Email for the users email... $EmailTo = "[email protected]"; and.... $Body .= "Email: "; $Body .= $Email; and at the bottom.... $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); There must be some way to put the $Email variable in the mail or $EmailTo so it sends the user a copy, No? Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/ Share on other sites More sharing options...
trq Posted May 5, 2014 Share Posted May 5, 2014 Have you looked at the first argument in the manual? http://php.net/mail Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478206 Share on other sites More sharing options...
fatboymills Posted May 5, 2014 Author Share Posted May 5, 2014 Ah so I add at the "mail" line toward the end of the script? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478211 Share on other sites More sharing options...
trq Posted May 5, 2014 Share Posted May 5, 2014 What does that have to do with the first argument? Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478212 Share on other sites More sharing options...
fatboymills Posted May 5, 2014 Author Share Posted May 5, 2014 Am I looking at the wrong code? Which argument? The one in MY script or the Manual? Thanks Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478225 Share on other sites More sharing options...
trq Posted May 5, 2014 Share Posted May 5, 2014 Am I looking at the wrong code? Which argument? The one in MY script or the Manual? I asked: Have you looked at the first argument in the manual? http://php.net/mail This is the description given for the first argument `to`. to Receiver, or receivers of the mail. The formatting of this string must comply with » RFC 2822. Some examples are: [email protected] [email protected], [email protected] User <[email protected]> User <[email protected]>, Another User <[email protected]> Still stuck? Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478238 Share on other sites More sharing options...
ginerjm Posted May 5, 2014 Share Posted May 5, 2014 The php manual is pretty clear on how to send CC and BCC of your mail. Why not read it and get a handle on using mail() ? Example #2 is especially detailed regarding your needs. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478241 Share on other sites More sharing options...
fatboymills Posted May 5, 2014 Author Share Posted May 5, 2014 Yup confused, I get the sending mail, but I want to send the mail to an email address recieved from the form thats stored in the $Email variable. (as well as myself) Sorry to bug you guys. Thanks Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478243 Share on other sites More sharing options...
ginerjm Posted May 5, 2014 Share Posted May 5, 2014 Am I hearing that you want us to help you pull an email address out of the body of some text from the form? Basically, that the 'other' email address is not coming to your script as a distinct element that you can simply add to your headers? UPON FURTHER REVIEW: I see now that you are posting the other email value($Email) to the body of your mail. Assuming that this is after you have processed the form and are preparing to send the mail, you REALLY need to read the manual as I suggested to see where you ought to be placing that variable, assuming that you have properly vetted it as valid input. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478245 Share on other sites More sharing options...
fatboymills Posted May 5, 2014 Author Share Posted May 5, 2014 Thats helpful, "go read the manual" I just wanted a little guidance. My mistake, I thought thats what these places were for. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478296 Share on other sites More sharing options...
ginerjm Posted May 5, 2014 Share Posted May 5, 2014 We can solve your problem right now but then when you have another problem, where will you be? Read the manual where it discusses how to use the mail function and you will be as smart as us when it comes to using mail().. Where will that put you? You make it sound like such hard work..... Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478298 Share on other sites More sharing options...
trq Posted May 5, 2014 Share Posted May 5, 2014 Assuming you have the two emails addresses you want to send to in the variables $Email and $EmailTo. To simply send the email to both of these addresses, just separate them by a comma as indicated in plain English in the manual page I linked to and the particular section I actually copied and quoted for you. $success = mail("$Email,$EmailTo", $Subject, $Body, "From: <$EmailFrom>"); Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478308 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 It is hard work.. for me anyway. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478319 Share on other sites More sharing options...
jazzman1 Posted May 6, 2014 Share Posted May 6, 2014 Why it's too hard for you to add a second email? Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478322 Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 I thought he meant it was too hard to read the manual.... Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478323 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 ok smart guys! this didn't to either send to either address,( adding the 2 variables separated by a comma) so I put the mail line in twice with each variable in it. Just hope it doesn't screw something else up. Thanks Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478342 Share on other sites More sharing options...
trq Posted May 6, 2014 Share Posted May 6, 2014 ok smart guys Just for that, your on my ignore list. Fend for yourself. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478344 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 What? Don't be so sensitive. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478354 Share on other sites More sharing options...
Strider64 Posted May 6, 2014 Share Posted May 6, 2014 What? Don't be so sensitive. Well, when you asking for help, it is better being nice than it is being rude. "You can catch more flies with honey than vinegar". Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478363 Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 Since you can't read English - or are afraid of manuals - you probably did screw it up. Either show us the code you tried (with an echo of the values used) or don't bother the people here with your attitude anymore. You made one of the most respected members here ignore you - that's quite an accomplishment for a newcomer. Says a lot about you Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478365 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 Ok, can somebody send my apologies to trq. I'm just so frustrated with this script. I didn't mean to offend. I appreciate the help guys. I need all the help I can get. Even though PHP frustrates me I love what this can do and enjoy scripting with it. I don't need to burn bridges with you guys. Sincerely, Fatboy. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478381 Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 So - now that we're past that - can you post the code you last tried along with the contents of the vars used to send the mail? You went wrong somewhere if you had to resort to calling the mail() function twice. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478385 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 This is what I have, however it DOES work. It sends results to me and also the form submitter... <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Needs Result"; function died($error) { // your error code can go here echo "Hmm, there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Results below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Needs: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers ); @mail($email_from, $email_subject, $email_message, $headers ); ?> <!-- include your own success html here --> Thanks, your Need has been sent. <?php } ?> Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478404 Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 1 - please use the proper code tags when posting code on a forum. On this one it is the word 'code' in square brackets with a closing tag of "/code" in brackets also. 2 - very bad form to develop code with functions buried in the middle of main stream (or any other code for that matter) code. Place them away from the rest of your code 3 - Why do you suppress the result of the call to mail()? How can you even possibly follow a suppressed statement with a message of success??? I had wished that you posted the code where you tried to send both emails in one call. That was your last complaint and that was I asked to see. Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478415 Share on other sites More sharing options...
fatboymills Posted May 6, 2014 Author Share Posted May 6, 2014 I didn't write the code I searched for it and tried to modify. I'm just trying to learn php, so I don't know what you mean by suppressed functions. Maybe I should start with a more reliable script? Link to comment https://forums.phpfreaks.com/topic/288241-php-send-mail/#findComment-1478421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.