コード例 #1
0
function formbuilder_process_email($form, $fields)
{
    global $_POST, $wpdb;
    $formBuilderTextStrings = formbuilder_load_strings();
    $email_sub = $form['subject'];
    // mai - added
    $email_msg = "";
    $autoresponse_required = false;
    $source_email = "";
    // Iterate through the form fields to add values to the email sent to the recipient.
    foreach ($fields as $field) {
        // Add the comments to the email message, if they are appropriate.
        if (trim($field['field_name']) != "" and $field['field_type'] != "recipient selection" and $field['field_type'] != "comments area" and $field['field_type'] != "followup page" and $field['field_type'] != "spam blocker" and $field['field_type'] != "page break" and $field['field_type'] != "reset button" and $field['field_type'] != "submit button" and $field['field_type'] != "submit image" and $field['field_type'] != "captcha field") {
            $email_msg .= strtoupper(decode_html_entities($field['field_name'], ENT_QUOTES, get_option('blog_charset'))) . ": " . decode_html_entities($field['value'], ENT_QUOTES, get_option('blog_charset')) . "\r\n\r\n";
            $field_values[$field['field_name']] = decode_html_entities($field['value'], ENT_QUOTES, get_option('blog_charset'));
            // Populate ~variable~ tags in the form subject with values submitted by the user
            $email_sub = str_replace("~" . $field['field_name'] . "~", $field_values[$field['field_name']], $email_sub);
            // mai - added
        } elseif ($field['field_type'] == "recipient selection") {
            // If we have a recipient selection field, change the form recipient to the selected value.
            if (preg_match('#' . FORMBUILDER_PATTERN_EMAIL . '#isU', trim($field['value']))) {
                $form['recipient'] = trim($field['value']);
            } else {
                $email_msg .= $formBuilderTextStrings['bad_alternate_email'] . " [" . trim($field['value']) . "]\n\n";
            }
        }
        // Get source email address, if exists.  Will use the first email address listed in the form results, as the source email address.
        if ($field['required_data'] == "email address" and !$source_email) {
            $source_email = $field['value'];
        }
    }
    // Add IP if enabled.
    $ip_capture = get_option('formBuilder_IP_Capture');
    if ($ip_capture == 'Enabled' and isset($_SERVER['REMOTE_ADDR'])) {
        $email_msg .= "IP: " . $_SERVER['REMOTE_ADDR'] . "\r\n";
    }
    $referrer_info = get_option('formBuilder_referrer_info');
    if ($referrer_info == 'Enabled') {
        // Add Page and Referer urls to the bottom of the email.
        if (isset($_POST['PAGE'])) {
            $email_msg .= "PAGE: " . $_POST['PAGE'] . "\r\n";
        }
        if (isset($_POST['REFERER'])) {
            $email_msg .= "REFERER: " . $_POST['REFERER'] . "\r\n";
        }
    }
    // Set autoresponse information if required and send it out.
    if ($source_email and $form['autoresponse'] != false and $autoresponse_required == false) {
        $sql = "SELECT * FROM " . FORMBUILDER_TABLE_RESPONSES . " WHERE id='" . $form['autoresponse'] . "';";
        $results = $wpdb->get_results($sql, ARRAY_A);
        $response_details = $results[0];
        $response_details['destination_email'] = $source_email;
        if ($response_details['from_email'] and $response_details['subject'] and $response_details['message'] and $response_details['destination_email']) {
            if ($response_details['from_name']) {
                $response_details['from_email'] = '"' . $response_details['from_name'] . '"<' . $response_details['from_email'] . '>';
            }
        }
        // Populate ~variable~ tags in the autoresponse with values submitted by the user.
        $txtAllFields = "";
        foreach ($field_values as $key => $value) {
            $response_details['subject'] = str_replace("~" . $key . "~", $value, $response_details['subject']);
            $response_details['message'] = str_replace("~" . $key . "~", $value, $response_details['message']);
            $txtAllFields .= $key . ": " . $value . "\n";
        }
        $response_details['subject'] = str_replace("~FullForm~", trim($txtAllFields), $response_details['subject']);
        $response_details['message'] = str_replace("~FullForm~", trim($txtAllFields), $response_details['message']);
        $result = formbuilder_send_email($response_details['destination_email'], decode_html_entities($response_details['subject'], ENT_QUOTES, get_option('blog_charset')), $response_details['message'], "From: " . $response_details['from_email'] . "\nReply-To: " . $response_details['from_email'] . "\n");
        if ($result) {
            die($result);
        }
    }
    // James' addition to ensure no hacking is allowed.
    $email_sub = preg_replace('#[^a-z0-9_ -]#isU', '', $email_sub);
    if (!$source_email) {
        $source_email = get_option('admin_email');
    }
    // Updated to force from address to use what is saved in settings.
    $formBuilder_Default_from = formbuilder_get_default_from();
    // Allow for old style messaging.
    if (strtoupper($formBuilder_Default_from) == '[SENDER_EMAIL]') {
        $formBuilder_Default_from = $source_email;
    }
    return formbuilder_send_email($form['recipient'], decode_html_entities($email_sub, ENT_QUOTES, get_option('blog_charset')), $email_msg, "From: " . $formBuilder_Default_from . "\nReply-To: " . $source_email . "\n");
}
コード例 #2
0
_e('To restore the old method of using the visitor\'s email address as the From address, enter this shortcode in the field: [SENDER_EMAIL]', 'formbuilder');
?>
</p>
			<?php 
if (!empty($_POST['formBuilder_Default_from'])) {
    $formBuilder_Default_from = $_POST['formBuilder_Default_from'];
    if (is_email($formBuilder_Default_from)) {
        formbuilder_set_default_from($formBuilder_Default_from);
    } elseif (strtoupper($formBuilder_Default_from) == '[SENDER_EMAIL]') {
        formbuilder_set_default_from($formBuilder_Default_from);
        echo "<span style='color: green;'>Restoring old functionality. WARNING: This may cause email not to be delivered to you properly.</span>";
    } else {
        echo "<span style='color: red;'>Invalid email address.</span>";
    }
}
$formBuilder_Default_from = formbuilder_get_default_from();
?>
			<form action="<?php 
echo FB_ADMIN_PLUGIN_PATH;
?>
&fbaction=settings" method="POST">
				<input type="text" width="40" name="formBuilder_Default_from" placeholder="email@<?php 
echo str_replace('www.', '', $_SERVER['HTTP_HOST']);
?>
" value="<?php 
echo htmlentities($formBuilder_Default_from);
?>
" />
				
				<input type="submit" name="Submit" value="<?php 
_e('Save', 'formbuilder');