...

View Full Version : A question about PHP Contact Forms



jgohil
08-16-2007, 09:33 PM
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 (http://www.smartofficeadvisors.com/contactus.php) 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/inventory/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!

Pennimus
08-16-2007, 10:11 PM
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
$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.

whizard
08-16-2007, 11:24 PM
But through that method (embedded/hidden email address), you'll get spammed mucho.

Dan

jgohil
08-17-2007, 04:03 AM
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:



$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!

Inigoesdr
08-17-2007, 08:47 PM
$_GET['ref'];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum