where("id", "=", $user_id) ->find_all(); $str_to_name = $userDetails[0]->name; } // If item_id is set, include a link to the item. $email_body = ""; if (!empty($item_id)) { $item = ORM::factory("item", $item_id); $email_body = "This message refers to type}s/{$item->id}") . "\">this page."; } // Make a new form with a couple of text boxes. $form = new Forge("contactowner/sendemail/{$user_id}", "", "post", array("id" => "g-contact-owner-send-form")); $sendmail_fields = $form->group("contactOwner"); $sendmail_fields->input("email_to") ->label(t("To:"))->value($str_to_name) ->id("g-contactowner-to-name"); $sendmail_fields->input("email_from") ->label(t("From:"))->value(identity::active_user()->email) ->id("g-contactowner-from-email") ->rules('required|valid_email') ->error_messages("required", t("You must enter a valid email address")) ->error_messages("valid_email", t("You must enter a valid email address")) ->error_messages("invalid", t("You must enter a valid email address")); $sendmail_fields->input("email_subject") ->label(t("Subject:"))->value("") ->id("g-contactowner-subject") ->rules('required') ->error_messages("required", t("You must enter a subject")); $sendmail_fields->textarea("email_body") ->label(t("Message:")) ->value($email_body) ->id("g-contactowner-email-body") ->rules('required') ->error_messages("required", t("You must enter a message")); // Add a captcha, if there's an active captcha module. module::event("captcha_protect_form", $form); // Add a save button to the form. $sendmail_fields->submit("SendMessage")->value(t("Send")); return $form; } public function emailowner($item_id) { // Display a form that a vistor can use to contact the site owner. // If this page is disabled, show a 404 error. if (module::get_var("contactowner", "contact_owner_link") != true) { throw new Kohana_404_Exception(); } // Set up and display the actual page. $view = new View("contactowner_emailform.html"); $view->sendmail_form = $this->get_email_form("-1", $item_id); print $view; } public function emailid($user_id, $item_id) { // Display a form that a vistor can use to contact a registered user. // If this page is disabled, show a 404 error. if (module::get_var("contactowner", "contact_user_link") != true) { throw new Kohana_404_Exception(); } // Set up and display the actual page. // Set up and display the actual page. $view = new View("contactowner_emailform.html"); $view->sendmail_form = $this->get_email_form($user_id, $item_id); print $view; } public function sendemail($user_id) { // Validate the form, then send the actual email. // If this page is disabled, show a 404 error. if (($user_id == "-1") && (module::get_var("contactowner", "contact_owner_link") != true)) { throw new Kohana_404_Exception(); } elseif (($user_id >= 0) && (module::get_var("contactowner", "contact_user_link") != true)) { throw new Kohana_404_Exception(); } // Make sure the form submission was valid. $form = $this->get_email_form($user_id); $valid = $form->validate(); if ($valid) { // Copy the data from the email form into a couple of variables. $str_emailsubject = Input::instance()->post("email_subject"); $str_emailfrom = Input::instance()->post("email_from"); $str_emailbody = Input::instance()->post("email_body"); // Add in some
tags to the message body where ever there are line breaks. $str_emailbody = str_replace("\n", "\n
", $str_emailbody); // Gallery's Sendmail library doesn't allow for custom from addresses, // so add the from email to the beginning of the message body instead. // Also add in the admin-defined message header. $str_emailbody = module::get_var("contactowner", "contact_owner_header") . "
\r\n" . "Message Sent From " . $str_emailfrom . "
\r\n
\r\n" . $str_emailbody; // Figure out where the email is going to. $str_emailto = ""; if ($user_id == -1) { // If the email id is "-1" send the message to a pre-determined // owner email address. $str_emailto = module::get_var("contactowner", "contact_owner_email"); } else { // or else grab the email from the user table. $userDetails = ORM::factory("user") ->where("id", "=", $user_id) ->find_all(); $str_emailto = $userDetails[0]->email; } // Send the email message. Sendmail::factory() ->to($str_emailto) ->subject($str_emailsubject) ->header("Mime-Version", "1.0") ->header("Content-type", "text/html; charset=utf-8") ->message($str_emailbody) ->send(); message::info(t("Your Message Has Been Sent.")); json::reply(array("result" => "success")); } else { // Set up and display the actual page. json::reply(array("result" => "error", "html" => (string) $form)); } } }