I want to email a copy of the webform submission to a product dealer selected by a database query on the user-supplied zip code, using a custom database of dealers by zip codes and emails.

I created a hidden field "dealer_email" and made it an email to field.

I cannot figure out a one-step process to assign the dynamic email value to the field for submission.

I am currently using a page break after the zip code field, and using validation processing to assign the selected email address to a session variable, which is then grabbed by the dealer_email field, using %session[demail], on the second page of the form.

I have tried these methods to set the form dealer_email field value.


$node->webform['dealer_email'] = "email@domain.com";
$form_state['values']['dealer_email'] = "email@domain.com";
$form_values['submitted_tree']['dealer_email'] = "email@domain.com"; (this is only post-submission, right?)

It could be a piped pair for the regular conditional recipient feature, but there are over a thousand values and they change monthly, so conditional recipients is not the best approach.

Comments

quicksketch’s picture

Status: Active » Closed (fixed)

Sorry you were not able to receive an answer to this request. Closing after lack of activity.

decibel.places’s picture

heh - forgot about this thread...

I am using code like this in the Advanced> Additional Processing field, it works...

I am using $_SESSION variables to pass values to a confirm page...

<?php
$zip = $form_values['submitted_tree']['zippostal_code'];
//try it
$result = db_query('SELECT * FROM zipcodestest WHERE Zip LIKE "' . $zip . '%"');
$rows = db_fetch_array($result);
if (strlen($rows['Legal Name'])){
	$_SESSION['dnear'] = 'Your nearest Company dealer is';
	$_SESSION['dname'] = $rows['Legal Name'];
	$_SESSION['dcity'] = $rows['City'];
	$_SESSION['dstate'] = $rows['State/Prov.'];
	$_SESSION['dphone'] = $rows['Phone'];
	$_SESSION['demail'] = $rows['WebleadEmail'];
}
else {
	if ((strlen($zip) >5) && (strpos($zip,"-"))) $zip = substr($zip, 0, 5);
	$result = db_query('SELECT * FROM zipcodestest WHERE Zip LIKE "' . $zip . '%"');
	$rows = db_fetch_array($result);
	if (strlen($rows['Legal Name'])){
		$_SESSION['dnear'] = 'Your nearest Company dealer is';
		$_SESSION['dname'] = $rows['Legal Name'];
		$_SESSION['dcity'] = $rows['City'];
		$_SESSION['dstate'] = $rows['State/Prov.'];
		$_SESSION['dphone'] = $rows['Phone'];
		$_SESSION['demail'] = $rows['WebleadEmail'];
		}else {
		$_SESSION['dnear'] = 'There is not a Company dealer near you, contact this dealer:';
		$_SESSION['dname'] = 'Company Default Dealer Name';
		$_SESSION['dcity'] = 'Default City';
		$_SESSION['dstate'] = 'Default State/Prov.';
		$_SESSION['dphone'] = 'Default Phone';
		$_SESSION['demail'] = 'defaultemail@domain.com';
		}
}

/* Send Customer Email */
$mailheaders = "From: Company Information \n";
$mailheaders .= "Reply-To: " . $_SESSION['demail'] . "\n\n";
$email_subject = "Company Information You Requested";
$customer_email = $form_values['submitted_tree']['email_address'];
$cbody = $_SESSION['dnear'] . "\n\n" . $_SESSION['dname'] . "\n" . $_SESSION['dcity'] . "\n" . $_SESSION['dstate'] . "\n" . $_SESSION['dphone'] . "\n" . $_SESSION['demail'];
mail("$customer_email", $email_subject, $cbody, $mailheaders);

/* Send Dealer Email */
$cname = $form_values['submitted_tree']['first_name'] . " " . $form_values['submitted_tree']['last_name'];
$caddress = $form_values['submitted_tree']['street_address'];
$ccity = $form_values['submitted_tree']['city'];
$cstate = $form_values['submitted_tree']['state'];
$czip = $form_values['submitted_tree']['zippostal_code'];
$cemail = $form_values['submitted_tree']['email_address'];
$ctime = $form_values['submitted_tree']['best_time_to_call'];
$ccphone = $form_values['submitted_tree']['cell_phone'];
$cphone = $form_values['submitted_tree']['home_telephone'];
$ccomments = $form_values['submitted_tree']['comments'];

$dbody = $cname . "\n" . $caddress . "\n" . $ccity . "\n" . $cstate . "\n" . $czip . "\n" . $cemail . "\n" . $cname . "\n" . $cphone . "\n" . $ctime . "\n" . $ccphone . "\n\nComments: \n" . $ccomments;

$mailheaders = "From: Company Lead Tracker \n";
$mailheaders .= "Reply-To: " . $cemail . "\n\n";
$email_subject = "Customer Request for Company Information";

mail($_SESSION['demail'], $email_subject, $dbody, $mailheaders);

?>
shaunwo’s picture

Did this code work for you? We have a similar request from one of our clients and we need to do something very similar... if this worked.

Please advise,
--
Shaun Worcester | senior webologist

design chemistry, llc | next generation web site design
p. 800 640 0424 x 105 | http://www.designchemistry.com/

Connect to me: http://www.google.com/profiles/shaun.daytonwebheads
Follow us on Twitter: http://twitter.com/daytonwebdesign
Become a fan on Facebook: http://www.facebook.com/daytonwebdesign

decibel.places’s picture

@shaunwo

that code was posted 1 1/2 years ago - it was tested before posting so it worked, of course you may need to customize it for your needs

hope it helps =)