Пример #1
0
/**
 * This constructs and sends the email from an individual email template for a single form
 * submission.
 *
 * @param integer $form_id
 * @param integer $submission_id
 * @param integer $email_id
 */
function ft_process_email_template($form_id, $submission_id, $email_id)
{
    list($success, $email_components) = ft_get_email_components($form_id, $submission_id, $email_id);
    if (!$success) {
        return array(false, "Email components not returned properly (ft_get_email_components).");
    }
    extract(ft_process_hook_calls("start", compact("form_id", "submission_id", "email_id", "email_components"), array("email_components")), EXTR_OVERWRITE);
    // if Swift Mailer is enabled, send the emails with that
    $continue = true;
    if (ft_check_module_enabled("swift_mailer")) {
        $sm_settings = ft_get_module_settings("", "swift_mailer");
        if (isset($sm_settings["swiftmailer_enabled"]) && $sm_settings["swiftmailer_enabled"] == "yes") {
            ft_include_module("swift_mailer");
            list($success, $message) = swift_send_email($email_components);
            $continue = false;
        }
    }
    // if it was sent (or was attempted to have been sent) by the Swift Mailer module, stop here
    if (!$continue) {
        return array($success, $message);
    }
    $eol = _ft_get_email_eol_char();
    $recipient_list = array();
    foreach ($email_components["to"] as $to_info) {
        $recipient_list[] = $to_info["recipient_line"];
    }
    $to = join(", ", $recipient_list);
    $to = htmlspecialchars_decode($to);
    if (empty($to)) {
        return array(false, "No main recipient specified.");
    }
    $headers = "MIME-Version: 1.0{$eol}";
    if (!empty($email_components["from"])) {
        $from = htmlspecialchars_decode($email_components["from"]["recipient_line"]);
        $headers .= "From: {$from}{$eol}";
    }
    if (!empty($email_components["reply_to"])) {
        $reply_to = htmlspecialchars_decode($email_components["reply_to"]["recipient_line"]);
        $headers .= "Reply-to: {$reply_to}{$eol}";
    }
    if (!empty($email_components["cc"])) {
        $cc_list = array();
        foreach ($email_components["cc"] as $cc_info) {
            $cc_list[] = $cc_info["recipient_line"];
        }
        $cc = join(", ", $cc_list);
        $cc = htmlspecialchars_decode($cc);
        $headers .= "Cc: {$cc}{$eol}";
    }
    if (!empty($email_components["bcc"])) {
        $bcc_list = array();
        foreach ($email_components["bcc"] as $bcc_info) {
            $bcc_list[] = $bcc_info["recipient_line"];
        }
        $bcc = join(", ", $bcc_list);
        $bcc = htmlspecialchars_decode($bcc);
        $headers .= "Bcc: {$bcc}{$eol}";
    }
    $message = "";
    $html_content = isset($email_components["html_content"]) ? $email_components["html_content"] : "";
    $text_content = isset($email_components["text_content"]) ? $email_components["text_content"] : "";
    $html_content = trim($html_content);
    $text_content = trim($text_content);
    // if there's no TO line or there's no email content for either types, we can't send the email
    if (empty($html_content) && empty($text_content)) {
        return array(false, "No text or HTML email content specified");
    }
    if (!empty($html_content) && !empty($text_content)) {
        $headers .= _ft_get_multipart_message($html_content, $text_content, $eol);
    } else {
        if (!empty($html_content)) {
            $message = $html_content;
            $headers .= "Content-type: text/html; charset=UTF-8";
        } else {
            if (!empty($text_content)) {
                $message = $text_content;
                $headers .= "Content-type: text/plain; charset=UTF-8";
            }
        }
    }
    $subject = $email_components["subject"];
    // send the email
    $email_sent = @mail("{$to}", $subject, $message, $headers);
    if ($email_sent) {
        return array(true, "");
    } else {
        return array(false, "The mail() function failed to send the email.");
    }
}
Пример #2
0
     break;
 case "unselect_all_submissions":
     $form_id = $request["form_id"];
     $_SESSION["ft"]["form_{$form_id}_select_all_submissions"] = "";
     $_SESSION["ft"]["form_{$form_id}_selected_submissions"] = array();
     $_SESSION["ft"]["form_{$form_id}_all_submissions_selected_omit_list"] = array();
     break;
 case "send_test_email":
     list($success, $message) = ft_send_test_email($request);
     $success = $success ? 1 : 0;
     echo "{ \"success\": \"{$success}\", \"message\": \"{$message}\" }";
     break;
 case "display_test_email":
     $form_id = $_SESSION["ft"]["form_id"];
     $email_id = $_SESSION["ft"]["email_id"];
     $info = ft_get_email_components($form_id, "", $email_id, true, $request);
     echo ft_convert_to_json($info);
     break;
 case "edit_submission_send_email":
     $form_id = $request["form_id"];
     $submission_id = $request["submission_id"];
     $email_id = $request["email_id"];
     list($success, $message) = ft_process_email_template($form_id, $submission_id, $email_id);
     if ($success) {
         $success = 1;
         $message = $LANG["notify_email_sent"];
     } else {
         $edit_email_template_link = "[<a href=\"{$g_root_url}/admin/forms/edit.php?form_id={$form_id}&email_id={$email_id}&page=edit_email\">edit email template</a>]";
         $success = 0;
         $message = $LANG["notify_email_not_sent_c"] . mb_strtolower($message) . " " . $edit_email_template_link;
     }