Page 1 of 1

**HELP WITH PHP EMAIL & SUBMIT BUTTON******************

Posted: Thu Apr 23, 2009 12:52 pm
by social
Hi everyone!

I AM HAVING MAJOR TROUBLE AND REALLY NEED SOME HELP. I HAVE A FORM THAT ALLOWS THE USER TO CLICK AND BUTTON TO BECOME A FAN OF A BUSINESS. WHEN THE BUTTON IS CLICKED, THE INFORMATION ABOUT THE USER IN SENT TO THE DATABASE AND AN EMAIL IS SENT TO THE BUSINESS SAYING THAT THEY HAVE A NEW FAN. THE PROBLEM IS WHEN I INCLUDED THE CODE: (isset($_POST['yourfan'])) TO CHECK IF THE BUTTON WAS CLICKED, THE FORM DOES NOT SEND THE EMAIL TO THE BUSINESS BUT WHEN I REMOVE THAT CODE, AN EMAIL IS SENT TO THE BUSINESS WHETHER OR NOT THE BUTTON IS CLICKED. WHAT DO I DO? I ONLY WANT THE EMAIL SENT ONLY WHEN THE IS BUTTON CLICKED. THE FULL CODE IS BELOW, PLEASE HELP!!! :banghead: :

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan">

<input name="yourfan" type="image" value="Submit" onClick="<?php
if (isset($_POST['yourfan']))
{
$to = $row_Bus['Email'];
$subject = 'You Have A Fan !';
$body = "blah...blah...blah.... ";
$headers = "From: admin@mysite.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$mail_sent = @mail( $to, $subject, $body, $headers );
}
?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/>
</label>
<input type="hidden" name="MM_insert" value="fan" />
</form>

Re: **HELP WITH PHP EMAIL & SUBMIT BUTTON******************

Posted: Thu Apr 23, 2009 2:27 pm
by Christopher
All caps, lots of asterisks in the title, code not put in code tags. These things decrease the chances of getting your question answered.

Re: **HELP WITH PHP EMAIL & SUBMIT BUTTON******************

Posted: Thu Apr 23, 2009 5:17 pm
by social
Oh okay...new to this forum....thanks for the hint.

Re: **HELP WITH PHP EMAIL & SUBMIT BUTTON******************

Posted: Thu Apr 23, 2009 6:14 pm
by Christopher
I think you probably want something like this:

Code: Select all

<?php 
$editFormAction = '';    // this should be the URL to this script
if (isset($_POST['yourfan'])) {
    $to = $row_Bus['Email'];
    $subject = 'You Have A Fan !';
$body = "blah...blah...blah.... ";
$headers = "From: admin@mysite.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
    $mail_sent = @mail( $to, $subject, $body, $headers ); 
?>
It's official! You are now a fan.
<?php
}  else {
?>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan">
<input name="yourfan" type="image" value="Submit" onClick=";MM_popupMsg(')" src="/FANBUT2.png" alt="Become A Fan"/>
<input type="hidden" name="MM_insert" value="fan" />
</form>
<?php
}
?>