Page 1 of 1

Need Help With PHP Mail

Posted: Thu Apr 23, 2009 5:25 pm
by social
Hi everyone,

I am very new to this forum and in desperate need of HELP! Please someone help! I have a code to allow users to become fans of a business. When they click the submit button I want the info inserted in the database and an email sent to the business saying that they have a fan. The problem is when I added the code

Code: Select all

if (isset($_POST['yourfan']))
to detect that the submit button was clicked, the info is sent to the database but email not sent. When i excluded the code, an email is sent to the business every time the page loads and whether or not the submit button is clicked. Please, please help...I only want it sent when the button is clicked...help anyone? :cry: My form code is below:

Code: Select all

<form action="<?php echo $editFormAction; ?>" method="POST" 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>
Thanks in advance!

Re: Need Help With PHP Mail

Posted: Thu Apr 23, 2009 6:10 pm
by deejay
hi

if this is the code for you form - then do you have another

Code: Select all

 
if (isset($_POST['yourfan']))
 


somewhere else on the page that contains your INSERT for the database. if so then i think this following code should sit in there.

Code: Select all

 
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 );
 }
 

Re: Need Help With PHP Mail

Posted: Thu Apr 23, 2009 6:31 pm
by social
Hi, Yes I do, the insert code is:

Code: Select all

//INSERT FAN---------------------------------------------------------------------------------------------
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fan")) {
$Fdate = date ("M. d, y");
$FANdate = $Fdate ;
  $insertSQL = sprintf("INSERT INTO BusFans (FanID, FanUname, FirstName, LastName, FanCity, FanState, FanBus, FanBusID, BusName, BusPict, BUsername, NumberFans, BusID, Category, Date, FanPict) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['memID'], "int"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['FirstName'], "text"),
                       GetSQLValueString($_POST['LastName'], "text"),
                       GetSQLValueString($_POST['FanCity'], "text"),
                       GetSQLValueString($_POST['FanState'], "text"),
             GetSQLValueString($_POST['FanBus'], "text"),
         GetSQLValueString($_POST['FanBusID'], "text"),
                       GetSQLValueString($_POST['BusName'], "text"),
       GetSQLValueString($_POST['buspict'], "text"),
          GetSQLValueString($_POST['buser'], "text"),
      GetSQLValueString($_POST['number'], "text"),
                       GetSQLValueString($_POST['BusID'], "int"),
                       GetSQLValueString($_POST['category'], "text"),
         GetSQLValueString($FANdate, "text"),
                       GetSQLValueString($_POST['FanPict'], "text"));
 
  mysql_select_db($database_BUSPROFILES, $BUSPROFILES);
  $Result1 = mysql_query($insertSQL, $BUSPROFILES) or die(mysql_error());
 
  $insertGoTo = "/busprofile-2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
So, you are saying that the mail code should go somewhere in here? Thanks in advance!

Re: Need Help With PHP Mail

Posted: Thu Apr 23, 2009 6:58 pm
by social
Hi, thanks for your help....I figured it out. I just did an external mail.php (which includes the codes to send the mail and insert into the database) and made the form action="mail.php". Thanks for your help! :D