creating a mail.php script that pulls email from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sqshymnky
    New Member
    • Jan 2008
    • 1

    #1

    creating a mail.php script that pulls email from database

    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
    // ************Beg in 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_P OST_VARS as $key => $value) {

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

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

    header("Locatio n: $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
  • pedalpete
    New Member
    • Oct 2007
    • 109

    #2
    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?proper ty=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

    Comment

    Working...