chandler Posted March 1, 2011 Share Posted March 1, 2011 Hi I am using the code below for an email form..I need to change sender's info, at the moment it displays sender (unknown) I would like it to display [email protected]... How can this be done. Thanks you for your help. $to = "[email protected]"; // subject $subject = ' email form ' . $subject; // the mail message $msg = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n" . "Message : \r\n$message"; mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"); $replymessage = "Hello $name message recieved -------------------------------------------------- Your Message: $message -------------------------------------------------- Thank you. "; $message = "name: $name \nQuery: $message"; mail("$replyemail", "$emessage", "From: $email\nReply-To: $email"); mail("$email", "Message: $subject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/ Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 assign "[email protected]" to your $mail variable and you should be good to go. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181199 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 hi, here's the complete code i had missed some out..I'm not sure but I don't think there is a $mail variable. Thanks for the help. <?php $error = ''; // error message $name = ''; // sender's name $email = ''; // sender's email address $message = ''; // the message itself $spamcheck = ''; // Spam check if(isset($_POST['send'])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $spamcheck = $_POST['spamcheck']; if(trim($name) == '') { $error = '<div class="errormsg">Please enter your name.</div>'; } else if(trim($email) == '') { $error = '<div class="errormsg">Please enter your E-mail?</div>'; } else if(!isEmail($email)) { $error = '<div class="errormsg">Incorrect Email format.!</div>'; } else if(trim($message) == '') { $error = '<div class="errormsg">Message please!</div>'; } else if(trim($spamcheck) == '') { $error = '<div class="errormsg">Please enter: Spam Check!</div>'; } else if(trim($spamcheck) != '5') { $error = '<div class="errormsg">Spam Check: Number incorrect! 2 + 3 = ???</div>'; } if($error == '') { if(get_magic_quotes_gpc()) { $message = stripslashes($message); } // the email will be sent here // make sure to change this to be your e-mail $to = "[email protected]"; // the email subject $subject = 'email form' . $subject; // the mail message ( add any additional information if you want ) $msg = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n" . "Message : \r\n$message"; mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"); $replymessage = "Hello $name We have recieved your message -------------------------------------------------- Your Message: $message -------------------------------------------------- Thank you. "; $message = "name: $name \nQuery: $message"; mail("$replyemail", "$emessage", "From: $email\nReply-To: $email"); mail("$email", "Message: $subject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; ?> <!-- Message sent! (change the text below as you wish)--> <div style="text-align:left;"> <p>Thank you <b><?=$name;?></b>, we will be in touch.</p> </div> <!--End Message Sent--> <?php } } if(!isset($_POST['send']) || $error != '') { ?> <!--Error Message--> <?=$error;?> Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181217 Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 sorry - I meant $email. Can you echo $email at the point you would send the mail and see what it has in it? Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181224 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 its got the email entered into the form by the person filling it out. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181230 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 that's if I did it right!, I have no idea when it comes to php. mail("$email", "Message: $subject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $email ; Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181234 Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 to see if the value is as you think it is, put this line just before your mail send script echo $email ; exit(); Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181237 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 yes it displays the email address i entered into the form Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181240 Share on other sites More sharing options...
cyberRobot Posted March 1, 2011 Share Posted March 1, 2011 Is the unknown sender coming from the last mail() functions: ... $message = "name: $name \nQuery: $message"; mail("$replyemail", "$emessage", "From: $email\nReply-To: $email"); mail("$email", "Message: $subject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; I don't see where $replyemail is being set. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181255 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 I don't know php, so I have no idea what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181257 Share on other sites More sharing options...
Muddy_Funster Posted March 1, 2011 Share Posted March 1, 2011 Is the unknown sender coming from the last mail() functions: ... $message = "name: $name \nQuery: $message"; mail("$replyemail", "$emessage", "From: $email\nReply-To: $email"); mail("$email", "Message: $subject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; I don't see where $replyemail is being set. Good Point There Cyber, Chandler, add a line, above the mail() function to assign your chosen email address to $replyemail $replyemail = "[email protected]" mail(.... Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181264 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 You guys are the best thank you, works perfect now.. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181393 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 one more thing if you can help please, I would like the form to refresh a few seconds after hitting the submit button..how is this done? thanks Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181417 Share on other sites More sharing options...
cyberRobot Posted March 1, 2011 Share Posted March 1, 2011 You could take a look at header(): http://php.net/manual/en/function.header.php The following example was pulled from the user contributions section: <?php header( "refresh:5;url=wherever.php" ); echo 'You\'ll be redirected in about 5 secs. If not, click <a href="wherever.php">here</a>.'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181424 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 thanks but that only refreshes the form page, I need to only refresh after form is submitted to reload the form again. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181432 Share on other sites More sharing options...
cyberRobot Posted March 1, 2011 Share Posted March 1, 2011 You'll need to add the code inside the if() portion which gets activated after the form is submitted. For example, you could insert it here: <?php ... $msg = "From : $name \r\ne-Mail : $email \r\nSubject : $subject \r\n" . "Message : \r\n$message"; mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"); /* REFRESH CODE HERE */ $replymessage = "Hello $name We have recieved your message ... ?> Just keep in mind that header() must be called before an output is displayed. Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181439 Share on other sites More sharing options...
cyberRobot Posted March 1, 2011 Share Posted March 1, 2011 Also, since you're sending out messages to an e-mail address entered by the user you should be careful of e-mail header injection attacks. http://www.google.com/search?q=php+e-mail+header+injection+attacks&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=&rlz=1I7ADFA_en Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181444 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 thanks Cyber, that did fix it, I guess this php stuff is addictive I keep wanting to do more to the script. I have added some java script for a countdown timer , so here is the problem hope you can help. after the form is submitted it reads like so: "You'll be redirected in 10 - countdown clock secs. If not, click here. Thank you, we will be in touch." I would like it to be displayed all on one line like so: "You'll be redirected in (10 - countdown clock secs). If not, click here. Thanks again for all your help header( "refresh:10;url=visit.php" ); echo 'You\'ll be redirected in '; ?> <script type="text/javascript"> seconds = 10; function decreaseTime(){ document.frm.submit.value=seconds; seconds--; if(seconds<0){ document.frm.submit.value='Submit'; document.frm.submit.disabled=false; return true; } setTimeout('decreaseTime()',1000); } window.onload = function() { document.frm.submit.value=seconds; setTimeout('decreaseTime()',1000); } </script> <form name="frm" action=""> <input type="submit" name="submit" disabled /> </form> <?php echo 'secs. If not, click <a href="visit.php">here</a>.'; Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181490 Share on other sites More sharing options...
Muddy_Funster Posted March 2, 2011 Share Posted March 2, 2011 how about adding a hidden field to your form, naming it "refresh" and giving it a value of "1". Then at the top of the page : $refresh = $_POST['refresh'] if ($refresh == 1){header( "refresh:5;url=wherever.php" ); echo 'You\'ll be redirected in about 5 secs. If not, click <a href="wherever.php">here</a>.'; $refresh = 0; } would that do the trick? Quote Link to comment https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181642 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.