Jump to content

form help please


chandler

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/
Share on other sites

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;?>

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181217
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181255
Share on other sites

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(....

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181264
Share on other sites

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>.';
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181424
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181439
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181444
Share on other sites

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>.';

 

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181490
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/229239-form-help-please/#findComment-1181642
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.