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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
social
Forum Newbie
Posts: 6
Joined: Thu Apr 23, 2009 12:42 pm

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

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
social
Forum Newbie
Posts: 6
Joined: Thu Apr 23, 2009 12:42 pm

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

Post by social »

Oh okay...new to this forum....thanks for the hint.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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
}
?>
(#10850)
Post Reply