SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I get this mysql data from the first script into the second script

    Okay I've been lurking for years but finally decided to ask for help publicly :-) Thanks to anyone in advance. basically I have config.php which will look for a $id in the url and if one is found it retrieves contact information from the database according to which $id was passed to the url....simple right?

    Well I have added this "mail form" snippet below to config.php and it works as expected.

    Code:
    <?PHP
       $contact_form = '<form method="post" action="sendeail.php">
    
    <!-- DO NOT change ANY of the php sections -->
    <?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    
    <input type="hidden" name="ip" value="<?php echo $ipi;?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi; ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti; ?>" />
    
    
    Your Name: <br />
    <input type="text" name="visitor" size="35" />
    <br />
    Your Email:<br />
    <input type="text" name="visitormail" size="35" />
    <br /> <br />
    <br />
    Attention:<br />
    <select name="attn" size="1">
    <option value=" Sales n Billing ">Sales n Billing </option>
    <option value=" General Support ">General Support </option>
    <option value=" Technical Support ">Technical Support </option>
    <option value=" Webmaster ">Webmaster </option>
    </select>
    <br /><br />
    Mail Message:
    <br />
    <textarea name="notes" rows="4" cols="40"></textarea>
    <br />
    <input type="submit" value="Send Mail" />
    <br />
    </form>'
    ?>
    I wanted "$contact_form" to show a contact form on the contact page....This works! I'm able to fill out the form and the mail will get sent to me....So far so good.

    Now, I need to change where the form gets emailed from my email address to
    ".$row['Name']." from "config.php" so that when the form is submitted it will be emailed to the email address for the corresponding "$id".

    I'm pulling my hair out trying to figure this out. Could anyone please give me their insight? or use their PHP Kung Fu and teach me a lesson? I have included both script's at the bottom of this thread.

    Here is config.php
    Code:
    <?php
    session_start();
    error_reporting(E_ALL);
    ini_set('display_errors',"on"); 
    
    /*set debug to TRUE to delete cookies and test changes to the script.
    set debug to FALSE to run in production environment.*/
    $debug = FALSE;
    // reset everything if debug is true
    if ($debug) {
    $_SESSION['contact_block'] = '';
    setcookie('affid','',1);
    $id='';
    echo "Debug is ON";
    die;
    }
    // we no longer use this cookie. Replaced by $_COOKIE['affid']
    if (isset($_COOKIE['id'])) {unset($_COOKIE['id']); }
    /*Logic:
    If an affiliate ID was passed to the URL as a GET, grab it and do a lookup.
    Otherwise, no affiliate, so display the default contact information.*/
    //echo "Site is in debug mode and under test by developer but still usable. Please ignore.<br />";
    if (isset($_GET['id'])) {
    //echo 'Right now $_GET[ID] is '.$_GET['id']."<br />";
    } else {//echo 'Right now $_GET[ID] is undefined'."<br />";
    }
    if (isset($_GET['id']))
    {$id = $_GET['id'];}
    elseif (isset($_COOKIE['affid'])) {$id = $_COOKIE['affid'];}
    else {$id = 0;}
    //echo "Now ID in config.php = ".$id."<br />";
    $contact_block = lookup($id);
    if (empty($contact_block)) {
    $contact_block = '<p>United States  Office: 410-727-6444</p>
              <p>Costa Rica Office US Line: 410-800-4773</p>
            <p>Costa Rica Office: 011-506-2778-7080</p>
              <p>Toll Free: 866-466-5623 </p>';
            $id = 0;}
    // set a cookie
    setcookie('affid', $id, time()+(3600*24*30),'/','.delpacifico.net');
    $_SESSION['contact_block'] = $contact_block;
    //echo 'Cookie in config.php = '.$_COOKIE['affid']."<br />";
    //echo 'Final ID = '.$id."<br />";
    ?>
    <?PHP
    function lookup($id=0) {
    // set default contact block in case affiliate no longer exists
    $contact_block='';
    if ($id > 0) {       
    // Establish database connection
    include("project/ewcfg6.php");
       $db = mysql_connect(EW_CONN_HOST,EW_CONN_USER,EW_CONN_PASS);
                  mysql_select_db(EW_CONN_DB);
       // get the contact information
       $sql = mysql_query("select * from affiliates where id = $id");
       $num_rows = mysql_num_rows($sql);
       if ($num_rows > 0){
       while($row = mysql_fetch_array( $sql )) {
       $contact_block = '<P>Name: '.$row['Name'].'<br />'.'Firm: '.$row['Firm'].'<br />'.'Phone: '.$row['Telephone'].'<br />'.   '<a href="mailto:'.$row['email'].'?bcc=info@delpacifico.net">Send Email</a></P>';
          }
          }
    }       
    return($contact_block);
    }    
    ?>
    <?PHP
       $contact_form = '<form method="post" action="sendeail.php">
    
    <!-- DO NOT change ANY of the php sections -->
    <?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    
    <input type="hidden" name="ip" value="<?php echo $ipi;?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi; ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti; ?>" />
    
    
    Your Name: <br />
    <input type="text" name="visitor" size="35" />
    <br />
    Your Email:<br />
    <input type="text" name="visitormail" size="35" />
    <br /> <br />
    <br />
    Attention:<br />
    <select name="attn" size="1">
    <option value=" Sales n Billing ">Sales n Billing </option>
    <option value=" General Support ">General Support </option>
    <option value=" Technical Support ">Technical Support </option>
    <option value=" Webmaster ">Webmaster </option>
    </select>
    <br /><br />
    Mail Message:
    <br />
    <textarea name="notes" rows="4" cols="40"></textarea>
    <br />
    <input type="submit" value="Send Mail" />
    <br />
    </form>'
    ?>

    Here is sendeail.php
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sendemail Script</title>
    </head>
    <body>
    
    <!-- Reminder: Add the link for the 'next page' (at the bottom) -->
    <!-- Reminder: Change 'YourEmail' to Your real email -->
    <?php
    $ip = $_POST['ip'];
    $httpref = $_POST['httpref'];
    $httpagent = $_POST['httpagent'];
    $visitor = $_POST['visitor'];
    $visitormail = $_POST['visitormail'];
    $notes = $_POST['notes'];
    $attn = $_POST['attn'];
    
    
    
    
    if (eregi('http:', $notes)) {
    die ("Do NOT try that! ! ");
    }
    if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
    {
    echo "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";
    echo $badinput;
    die ("Go back! ! ");
    }
    
    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<h2>Use Back - fill in all fields</h2>\n";
    die ("Use back! ! ");
    }
    
    $todayis = date("l, F j, Y, g:i a") ;
    
    $attn = $attn ;
    $subject = $attn;
    
    $notes = stripcslashes($notes);
    
    $message = " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";
    
    $from = "From: $visitormail\r\n";
    
    
    mail("adrian@delpacifico.net", $subject, $message, $from);
    
    header( "Location: removed because of stupid URL rule." ); 
    
    ?>
    
    <p align="center">
    Date: <?php echo $todayis ?>
    <br />
    Thank You : <?php echo $visitor; ?> ( <?php echo $visitormail; ?> )
    <br />
    
    Attention: <?php echo $attn; ?>
    <br />
    From:<?php echo $from; ?>
    <br />
    Message:<br />
    <?php $notesout = str_replace("\r", "<br/>", $notes);
    echo $notesout; ?>
    <br />
    <?php echo $ip ;?>
    
    <br /><br />
    <a href="contact.php"> Next Page </a>
    </p>
    
    </body>
    </html>
    Last edited by kelbizzle; Oct 12, 2009 at 07:25. Reason: typo's

  2. #2
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is what you are tryinng to do.

    mail($row['email'], $subject, $message, $from);

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that's what I would like to do. Unfortunately it isn't working for me.

    The script completes fine, but the email is never received.

    hmmmm...this is strange. If I put in my email address

    Code:
    mail("adrian.k.matthews@gmail.com", $subject, $message, $from);
    The email get sent no problem. Any other ideas?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •