kelbizzle Posted October 9, 2009 Share Posted October 9, 2009 Okay, Hello I've been trolling for years. This the first time I've ever asked for php help. Normally my questions seem so amateur when I finally find theanswer on my own. But this is making me pull my hair out. Hopefully someone can help me. I currently have a php script that will look for a referral id in the url. If one is found..it displays the contact information of the referrer. I have modified the script so in addition to it showing the contact information. It will also show a contact form on the "contact us page" What I can't figure out is how to get the email address from the database into this form. Could someone take a look? When I use mail($row['email']...ect. The script will complete but the mail will not come to the email address in the database. Here is the code: This is config.php which looks for the id and displays the contact block and the email for on the contact page. <?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>'; } while($row2 = mysql_fetch_array( $sql )) { $contact_email = $row2['email']; } } } 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>' ?> This is the email script that's called when the user submits the form <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("kelbizzle@mailinator.com", $subject, $message, $from); header( "Location: http://www.delpacifico.com/thanks.php" ); ?> <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> Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/ Share on other sites More sharing options...
Bricktop Posted October 9, 2009 Share Posted October 9, 2009 Hi kelbizzle, Not 100% sure what you're asking here so apologies if this isn't what you need but have you tried assigning $row['email'] as a value to the "visitormail" input field? i.e. <input type="text" name="visitormail" value="'.$row['email'].'" size="35" /> Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933774 Share on other sites More sharing options...
kelbizzle Posted October 9, 2009 Author Share Posted October 9, 2009 Oh okay. I'm sorry I really should clarify. I need the sendeail.php form to send to the email address of the referrer. <?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); } ?> I need the form to send to this address '.$row['email'].' that's pulled from the database of referrers. The visitormail is so I'll know who the email came from. Thanks in advance for anyone taking the time to help me. I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933782 Share on other sites More sharing options...
Bricktop Posted October 9, 2009 Share Posted October 9, 2009 Hi kelbizzle, You could store the $row['email'] in a hidden field and then grab that on sendeail.php. So, on config.php change your code to read: $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> <input type="hidden" name="referreremail" value="'.$row['email'].'" /></P>'; and then on sendeail.php change your code to read: $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes']; $attn = $_POST['attn']; $referreremail = $_POST['referreremail']; Then, the referrers email address is stored in the $referreremail variable which you can use with PHP's mail() function to send to that address. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933786 Share on other sites More sharing options...
kelbizzle Posted October 9, 2009 Author Share Posted October 9, 2009 Darn, that doesn't seem to work. The email is never received. The script completes fine. Did I do anything wrong? config.php <?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> <input type="hidden" name="referreremail" value="'.$row['email'].'" /></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>' ?> sendeail.php <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']; $referreremail = $_POST['referreremail']; 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($referreremail, $subject, $message, $from); header( "Location: http://www.delpacifico.com/thanks.php" ); ?> <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> Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933795 Share on other sites More sharing options...
mikesta707 Posted October 9, 2009 Share Posted October 9, 2009 I dont see any place where you call the lookup function (which is where the hidden field is.) I dont actually even see where you put the beginning for tag. I do see t his bit of code <?PHP $contact_form = '<form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); which, besides being completely invalid, won't echo the beginning form tag. if you want to echo it, put an echo <?php $contact_form = '<form method="post" action="sendeail.php">; echo $contact_form; ?> do note that I fixed the invalid markup also. and if you want to the hidden field to be a part of that form, you have to echo it also. having a function won't do anythign if you don't call it 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 /> <?php echo lookup(); ?> Mail Message: <br /> <textarea name="notes" rows="4" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form>' Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933803 Share on other sites More sharing options...
kelbizzle Posted October 9, 2009 Author Share Posted October 9, 2009 I dont see any place where you call the lookup function (which is where the hidden field is.) I dont actually even see where you put the beginning for tag. I do see t his bit of code <?PHP $contact_form = '<form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); which, besides being completely invalid, won't echo the beginning form tag. if you want to echo it, put an echo <?php $contact_form = '<form method="post" action="sendeail.php">; echo $contact_form; ?> do note that I fixed the invalid markup also. and if you want to the hidden field to be a part of that form, you have to echo it also. having a function won't do anythign if you don't call it 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 /> <?php echo lookup(); ?> Mail Message: <br /> <textarea name="notes" rows="4" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form>' config.php get's called when the page is loaded. The form shows up as expected. When I change it to what you suggested. The page won't load at all. Any other suggestions? The first form tag is listed here. $contact_form = '<form method="post" action="sendeail.php"> The form shows fine. Here is a url to see. http://www.delpacifico.net/aff_contact_test.php?id=12 Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-933823 Share on other sites More sharing options...
kelbizzle Posted October 14, 2009 Author Share Posted October 14, 2009 Does anyone else have anymore ideas? I'd pay $20 bucks to get this solved today. Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-936825 Share on other sites More sharing options...
isedeasy Posted October 14, 2009 Share Posted October 14, 2009 When I look in the source of the page you posted I can still see the PHP. <?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; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-936836 Share on other sites More sharing options...
kelbizzle Posted October 14, 2009 Author Share Posted October 14, 2009 Okay, I've fixed that part. The php isn't seen. but the Mail part isn't working. <?PHP $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); $contact_form = '<form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <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; ?>" /> It works when I use my email address. mail("adrian@mailinator.com", $subject, $message, $from); but not when I try to get the email address from the database. mail("$row['email']", $subject, $message, $from); Quote Link to comment https://forums.phpfreaks.com/topic/177102-php-referral-database-i-would-like-this-form-to-email-the-referrer/#findComment-936859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.