By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,929 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,929 IT Pros & Developers. It's quick & easy.

creating a mail.php script that pulls email from database

P: 1
Hello all,

I know html but am sort of lost when it comes to PHP. I don't really know where to even begin to explain my problem.

I am working on a site that deals with real estate. I have created a form on a basic html page( real estate listing page). This form calls a mail.php page to send the contents of the form to the person to whom it is supposed to go (property owner). I setup a test and it all works fine. But here is where the problem begins.

The form I created is on about one hundred pages( for each of the different properties) and they each need to go to different email addresses (property owner of the specific house). The owner's email address is in the database and I have the name of the field. I do not know how to get the mail.php page to "call" the database and insert the email address. I believe that the database we use is Perl. I also need to add a bcc: area in the code but I am not sure how.

The code is below.


[code] <?php
// ************Begin Configure***************
//Put where you want the email to go
$mailto = "me@myemail.com";
//Put your subject in here
$subject = "Real estate Inquiry";
//Put where to redirect to after sending the email
$redirect = "thank_you.html";
// ************End Configure****************


foreach($HTTP_POST_VARS as $key => $value) {

$message .= $key . ': ' . $value;
$message .= "\n"; //Note the double quotes

}
if (@mail($mailto, $subject, $message)) {

header("Location: $redirect");
} else {
// This echo's the error message if the email did not send.
// You could change the text in between the <p> tags.
echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?> [code]

Thank you very much for any help.

Lauren
Jan 31 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 110
Hi Lauren,

To start with, I suspect your database is not Perl, as Perl is a programming language, and as far as I know, not a database.

Now, as far as getting the e-mail addresses and bcc for the mail page, I suspect you are either using different domains, or page variables from the page which the form was linked to. Eg. does your mail.php?property=PROPERTY_ID or something like that?

You can then use the property_id in a query on the mail page so you can find the correct e-mail address from the database.
If you are using different domains, you can use $_SERVER['HTTP_HOST']
to get the domain name and then pass that into the query to get the e-mail address.

I hope that helps.
Pete
Feb 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.