Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question A question about PHP Contact Forms

    I'm using the Blog component of Joomla as bit of a product catalog. It works well for what I need as we don't sell anything directly from the site, but I need a way to add a "Get A Quote" button that launches a mail form.

    I've got a mail form that I can have it go to, but my question is, how can I add the product page it came from as a variable? The idea is, someone is browsing our products and clicks a link to 'get more info' - this launches the contact form in which they can fill out their e-mail address and add a message, but the product they were viewing is already added to the subject or a 'product' field.

    I hope that makes sense...

    The site is:

    http://www.smartofficeadvisors.com/i.../As-Is-Systems

    The nice thing is, Joomla! already has a way to e-mail that particular item to someone, but I can't find a way to have it automatically come to a specific e-mail address rather than allow the user to type in an e-mail to send to. Any suggestions would be greatly appreciated.

    Thanks!

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    You are going to need to do some editing of Joomlas mailing script.

    In your quote link on the product page, add a query string to the URL such as ?ref=productname.

    Then on the quote contact form page, you just need a simple bit of PHP to retrieve this query string and put it into your form field.

    PHP Code:
    <?php
    $referring_page 
    $_GET['ref'];
    echo 
    '<input id="subject" type="text" value="'.$refering_page.'" />';
    ?>
    The more difficult part is going in to your mailscript (to find it, look for the name of the script in the action of the form) and adding another element to be emailed to you. You should be able to work that out though, based on what's already there.

    --

    As for the second question, a simple way to do it would be to hide the email input with CSS and hardcode the email address you want to send to in the value of the input. Else, you need to go into the mailscript again to edit things.

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    But through that method (embedded/hidden email address), you'll get spammed mucho.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the detailed response! I think I'll leave the Joomla! mail function alone and just use my existing contact page with the code you provided. This is my mailing script code:

    Code:
    $smtp = Mail::factory('smtp', array ('host' => 'mail.mydomain.com',
    'auth' => true,
    'username' => 'smtpuser@domain.com' ,
    'password' => 'password'));
    
    $to = 'message_recipient@domain.com' ;
    $from = 'sender_address@domain.com';
    $name = $_REQUEST['Name'] ;
    $subject = "Get a Quote"; 
    $headers = array ('From' => $from, 
                'To' => $to, 
                'Subject' => $subject);
    
    $fields = array();
    $fields{"Name"} = "Name";
    $fields{"Item"} = "Item";
    $fields{"Email"} = "Email";
    $fields{"Phone"} = "Phone";
    $fields{"Message"} = "Message"; 
    
    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
    
    
    $subject2 = "Thank you for contacting Smart Office Advisors";
    $to2 = $_REQUEST['Email'];
    $autoreply = "Thank you for contacting us.
    Someone from our office will contact you within 24 hours regarding your inquiry.";
    $headers2 = array ('From' => $to,
                'To' => $to2,
                'Subject' => $subject2);
                
                
    if($Email == '') {print "You have not entered an email, please go back and try again";}
    else 
    {
    	
    	if($name == '') {print "You have not entered a name, please go back and try again";} 
    	else
    	{
    		
    		$send = $smtp->send($to, $headers, $body);
    		$send2 = $smtp->send($to2, $headers2, $autoreply); 
    
    		if(PEAR::isError($send))
    		{
    			print "We encountered an error sending your mail, please notify support@domain.com";
    		}
    		else
    		{
    			header( "Location: http://www.smartofficeadvisors.com/product_thankyou.php" );
    		}
    	}
    }
    Could you please let me know how to reference the 'productname' variable passed from the link? I think I know where to insert it, but I'm not sure how to reference it.

    Once I get that part, I'll just add a link (button) to each of the listings with a unique 'productname' - sound right?

    Thanks again for all the help!
    Last edited by jgohil; 08-17-2007 at 04:17 AM. Reason: Added Code

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    $_GET['ref'];
    Last edited by Inigoesdr; 08-17-2007 at 08:48 PM. Reason: Fixed index name..


  •  

    Posting Permissions

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