Jump to content

[SOLVED] Can't understand why this function won't function


simcoweb

Recommended Posts

Ok, I have a form that when submitted submits all the data to MySQL and then sends out an email to each party if query is successful. Pretty straightforward stuff. I have an 'include' file that holds my database parameters AND my functions. So, I have this function in the included file:

 

// send email results and confirmation function
function send_mails() {
  // start mail process
$mailContent="--------CONTACT--------\n"
            ."Name: ".$name."\n"
            ."Date: ".$date."\n"
            ."E-mail: ".$email."\n\n--------PHONE--------\n"
            ."Phone: ".$phone."\n"
            ."Address: ".$address."\n"
		."City: ".$city."\n"
		."State: ".$state."\n"
		."Zip: ".$zip."\n\n---------Other Details---------\n"
		."When are you moving: ".$moving."\n"
		."Where are you moving: ".$where."\n"
		."Your price range: ".$price."\n"
		."Number of bedrooms: ".$bedrooms."\n"
		."Square footage: ".$sqft."\n"
		."Comments: ".$comments."\n";
//----------------------------------
$toAddress="[email protected]"; /* change this! */
$subject="Seattle Viet Homes Buyer Inquiry"; /* change this! */
$recipientSubject="Seattle Viet Homes Buyer Inquiry"; /* change this! */
$receiptMessage = "Thank you ".$name." for inquiring at SeattleVietHomes.com's website!\n\n\nHere is the contact information you submitted to us:\n\n"
            ."--------CONTACT--------\n"
            ."Name: ".$name."\n"
            ."E-mail: ".$email."\n"
            ."Phone: ".$phone."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
}

 

Then, in my form page I have this code to run the function IF the query is successful and no errors. Everything else works but the emails don't get sent. here's the function call:

 

$results = mysql_query($sql) or die(mysql_error());
if (mysql_affected_rows($dbc) == 1){

// Send the E-Mail
send_mails();

// redirect to confirmation page
  header("Location: confirmation.htm");
} else {
  header("Location: error.htm");
}

 

If I take the send_mail(); code and put it into the form page it works fine. I'm not understanding why it won't work if I 'call' the function from another file. Ideas?

eh...

function send_mails() {

  // start mail process

$mailContent = "--------CONTACT--------\n";
$mailContent .= "Name: ".$name."\n";
$mailContent .= "Date: ".$date."\n";
$mailContent .= "E-mail: ".$email."\n\n--------PHONE--------\n";
$mailContent .= "Phone: ".$phone."\n";
$mailContent .= "Address: ".$address."\n";
$mailContent .= "City: ".$city."\n";
$mailContent .= "State: ".$state."\n";
$mailContent .= "Zip: ".$zip."\n\n---------Other Details---------\n";
$mailContent .= "When are you moving: ".$moving."\n";
$mailContent .= "Where are you moving: ".$where."\n";
$mailContent .= "Your price range: ".$price."\n";
$mailContent .= "Number of bedrooms: ".$bedrooms."\n";
$mailContent .= "Square footage: ".$sqft."\n";
$mailContent .= "Comments: ".$comments."\n";

/*--------------------------------------------------------------*/

$toAddress = "[email protected]"; // change this! 
$subject = "Seattle Viet Homes Buyer Inquiry"; // change this!
$recipientSubject = "Seattle Viet Homes Buyer Inquiry"; // change this! 
$receiptMessage = "Thank you ".$name." for inquiring at SeattleVietHomes.com's website!\n\n\n";
$receiptMessage .= "Here is the contact information you submitted to us:\n\n";
$receiptMessage .= "--------CONTACT--------\n";
$receiptMessage .= "Name: ".$name."\n";
$receiptMessage .= "E-mail: ".$email."\n";
$receiptMessage .= "Phone: ".$phone."\n";

/*--------------------------------------------------------------*/

mail($email, $subject, $receiptMessage,"From:$toAddress");

/*--------------------------------------------------------------*/

mail($toAddress,$recipientSubject,$mailContent,"From:$email");
}

Ahhh, ok. This goes back to one of my earlier lessons...about 'global' declarations within a function. So, if i'm on track with this, I need to declare those variables as 'global' in order to have them populate plus execute. Correct?

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.