Jump to content

Recommended Posts

I am attempting to display all php variables from a form onto a different page which works fine.  On this page, I want the user to review the information and then press a button to send the information via email.

 

I am trying to use a php if statement that checks to see if a variable is set, if it is set to 1 then the mail will send using the php mail function. 

 

The problem is that when the page loads the mail is set even though the php variable is set to 0 and not 1.

 

Here is my code:

 

$button = 0;

 

//button used as link to end page and used to set $button = 1

<a href="employee_hours_finish.html"><button name="Send Hours" type="button" onclick="<?php $button = 1; ?>" >Send Hours</button></a>

 

<?php

if($button == 1){

mail($to,$subject,$message,$headers);

}

else{}

?>

 

Once again, mail($to,$subject,$message,$headers); is called regardless of what $button is set to.

Link to comment
https://forums.phpfreaks.com/topic/150615-php-if-statement-does-not-work/
Share on other sites

if(isset($_POST['submit'])){
   $to = $_POST['to'];
   $subject = $_POST['subject'];
   $message = $_POST['message'];
   $headers = "headers";
   if(mail($to,$subject,$message,$headers)) {
      echo "mail sent";
   } else {
      echo "error occured";
   }
}
?>

</pre>
<form action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>" method="POST">
To: 

Subject: 

Message: 


<

This solutions work but not with the logic i'm trying to invoke for my client.

 

Here is what needs to happen.

 

1.  user enters information on form, form is submitted to itself for error checking, if no errors the information is displayed on new page for customer to review.

 

2.  after the customer reviews, they press submit button, this sends a php mail using all the variables from the form on the previous page.

 

Problems that I need help with:

 

1.  I try to delay the <?php mail($to,$subject,$body) ?> function by using a button and an if statement to invoke, but the mail is sent regardless of the conditions of the if statment.

 

2.  I try to remedy this by using a new form, and using  if(isset($_POST['submit'])){ and the following form code,

 

<form method="get" name="email" action="<?php echo $PHP_SELF;?>">

<input class="submit" type="submit" name="submit" type="button" value="Send Hours">

</form>

<?php

 

if (isset($_GET['submit'])) {

  mail($to,$subject,$message,$headers);

}

 

?>

 

This sends the mail but it does not contain the variable information, it sends a blank email.

 

How can I get the variable information to show up in the email, it seems that it is lost when i press submit on the second page.

This sends the mail but it does not contain the variable information, it sends a blank email.

 

Of course it sends a blank email, you're using variables that don't have any values!

 

You should use the POST method when dealing with forms...

 

</pre>
<form method="get">

 
should be:
 
[code]

 
And when you get the submission you have to retrieve these values with the method you stated in your form, POST.  Where do these values come from?
 
[code]$to,$subject,$message,$headers<
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.