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="harrylips@gmail.com"; /* 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?

Link to comment
Share on other sites

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 = "harrylips@gmail.com"; // 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");
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.