1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
<?php require_once("../../admin/includes/init_page_public.php"); require_once("../../admin/classes/class.phpmailer.php"); $test_mode = true; if($test_mode){ $user_name = 'Rex'; $subject = 'test'; $content = 'content'; }else{ $param_array = $_POST; $user_name = $util->filterArrayValue($param_array, 'user_name', 'User Name', 'text', true); $email = $util->filterArrayValue($param_array, 'email', 'email', 'text', true); $subject = $util->filterArrayValue($param_array, 'subject', 'subject', 'text', true); $content = $util->filterArrayValue($param_array, 'content', 'content', 'text', true); } $err = $util->err; if(strlen($err) > 0){ //$err = 'Format of parameter is invalid'; $errCode = 3; } if(strlen($err) == 0 && $errCode == 0){ try{ $contacts = $db->get_option('contacts'); if($util->isEmpty($contacts)) throw new Exception("目前無法寄送Email"); $contacts = json_decode($contacts, true); }catch(Exception $e){ $err = $e->getMessage(); $errCode = 9; } } if(strlen($err) == 0 && $errCode == 0){ try{ $mail= new PHPMailer(); $mail->From = $email; $mail->FromName = $user_name; $mail->Subject = $subject; $mail->Body = $content; foreach($contacts as $contact){ $mail->AddAddress($contact['url'], $contact['title']); } $result = $mail->Send(); if(!$result) throw new Exception("目前無法寄送電子郵件,請稍侯再試"); }catch(Exception $e){ $err = $e->getMessage(); $errCode = 9; } } //Write XML response header("content-type:application/xml;charset=utf-8"); $output = '<?xml version="1.0" encoding="utf-8"?>'; $output .= '<root><status>'; if(strlen($err) == 0 && $errCode == 0){ $output .= '<code>true</code>'; $output .= '<detail>Action is completed</detail>'; }else{ $output .= '<code>false</code>'; $output .= '<detail file="' . $errFile . '" code="' . $errCode . '" lang="' . $lang . '">' . '<![CDATA[' . $err . ']]></detail>'; } $output .= '</status>'; $output .= '</root>'; echo $output; ?> |