ezee ajax phpmailer
1.0.0
PHPMailer 的易於使用的介面,採用 JSON 物件並透過電子郵件發送值,並使用 JSON 進行回复
config.php
值send-email.php
這個項目非常有主見。如果大多數人認為改變有用,我會很樂意遵守。否則,請隨意打開 PR 或提交想法。
'encryption_type'
,則SMTPSecure
也不會value
設為某個值,即使只是一個空字串。否則value
將預設為null
,失敗條件includes/create-default-email-body.php
如果JSON 提交的鍵的開頭(用破折號分隔)與這些字串之一匹配,則用於驗證/清理該值的格式將自動設置為此處顯示的相應格式(如果JSON 數組中未傳遞“格式” )。
範例: "phone-cell"
、 "phone-home"
和"phone-intergalactic"
鍵下的值將被驗證/解析為電話號碼,除非明確設定了它們的“格式”。
// Default keys on the server
$ default_key_formats = [
' name ' => ' text ' , // or string
' phone ' => ' phone ' ,
' email ' => ' email ' ,
' link ' => ' url ' ,
' url ' => ' url ' ,
' float ' => ' float ' ,
' int ' => ' int ' ,
' num ' => ' int '
];
如果未發送格式,則預設為「文字」。您可以透過在陣列中發送它們來覆蓋預設格式(請參閱上文)
{ // Pretend this is the JSON sent
"name" : "Man Guy" ,
// -- OR ---
"name" : {
"format" : "text" ,
"value" : "Man Guy"
} ,
"email" : "[email protected]"
// -- OR ---
"email" : {
"format" : "email" ,
"value" : "[email protected]"
} ,
// -- ETC ---
"phone" : {
"format" : "phone" ,
"value" : "(555) 555-5555"
}
}
所有回應均採用 JSON 格式,且(大部分)符合 JSend 回應格式。 「失敗」(有資料)或「成功」的"status"
」總是會傳回"raw"
金鑰下接收到的資料不變,而「失敗」狀態則設定"failed"
下金鑰失敗的原因
{ // Server errors
"status" : "error" ,
"message" : "Error message"
}
{ // User errors
"status" : "fail" ,
"data" : {
// Holds keys of any values that failed and their failure message
"failed" : {
"phone" : "Invalid format" ,
"email" : "Invalid format" ,
"message" : "No value recieved" ,
"favorite-food" : "Required; no key sent" ,
"hidden-field" : "Value did not match required value" ,
/*,...etc*/
} ,
// Values the server received(unchanged)
"raw" : {
"name" : "(Raw value)" ,
"phone" : "(Raw value)" ,
"email" : "(Raw value)"
// ...etc
} ,
// The values after being sanitized
"sanitized" : {
"name" : "(Sanitized value)" ,
"phone" : "(Sanitized value)" ,
"email" : "(Sanitized value)"
}
}
}
-或者-
{ // User errors
"status" : "fail" ,
"message" : "Error message"
}
{ // Success
"status" : "success" ,
"data" : {
// Values the server received
"raw" : {
"name" : "(Raw value)" ,
"phone" : "(Raw value)" ,
"message" : "(Raw value)"
// ...etc
} ,
// The values after being sanitized
"sanitized" : {
"name" : "(Sanitized value)" ,
"phone" : "(Sanitized value)" ,
"email" : "(Sanitized value)"
}
}
// Values will be sanitized as per their format before being emailed.
}
// All addresses can be formatted as an array with shape
// ['[email protected]', 'A name to send by']
// GLOBAL['ezee_email_vals'][('post-key')] holds all sanitized input values if everything goes well
global $ ezee_email_vals ;
$ name = $ ezee_email_vals [ ' name ' ];
$ email = $ ezee_email_vals [ ' email ' ];
$ message = $ ezee_email_vals [ ' message ' ];
// SMTP is always true
// Configuration for where the email will be sent from (required)
$ ezee_email_send_from_config = [
' encryption_type ' => ' tls ' , // (optional) 'ssl' or 'tls'
' port ' => 587 ,
' server ' => ' smtp.gmail.com ' , // Can also take secondary server separated by a comma
' email ' => ' [email protected] ' , // Email address on server
// or ['address', 'name'](name will be applied to send_as)
' password ' => '' // Password for address server
'send_as' => '[email protected]' // (optional) defaults to value in 'email'
// or ['address', 'name']
];
// Config for where the email will be sent to (required)
$ ezee_email_send_to_config = [
// NOTE: If using a name for the first address, this must
// be an array of arrays.
// Otherwise it will try to send the 'name' an email, resulting in failure.
' addresses ' => ' addresses ' => [
' [email protected] ' ,
[ ' [email protected] ' , ' Man Guy ' ],
[ ' [email protected] ' , ' Mr Stark ' , true ] // <-- Will be CC
],
// [email protected]
// ['[email protected]', 'Maximus Prime']
/* Multiple addresses can be specified, defaults to BCC for each address after the first(see notes)
[
// Setting the third array value (or array[2]) to 'true' will make the email CC
['[email protected]', 'Maximus Prime', true],
['[email protected]', 'Maximus Prime']
]
*/
' subject ' => " Contact from $ name " , // Sanitized values can be used here(see above)
' reply_to ' => ' [email protected] ' // (optional)
// ['[email protected]', 'my name']
];
// Flags and required values for POSTed JSON (required)
$ ezee_email_value_options = [
// Only email values under 'required_vals' keys (default true)
' limit_to_required ' => true ,
// Request fails if 'limit_to_required' is true (default true)
// and more inputs than required are posted
' fail_on_value_overload ' => false ,
// Required posted keys and values
// If required value is set to null, the received value can be anything(*anything but null).
' required_values ' => [
// e.g., the 'name' key could hold a number, or text
' name ' => null ,
/* This is for if you have an optional input, like a
message, that may or may not be submitted at all */
' optional-val ' => ' (opt) ' ,
// For clarity: this would be like a text box with
// the 'name' set to 'two-plus-two' and value set to '4'
' two-plus-two ' => ' 4 ' ,
]
];
// is_html defaults to true, and uses msgHTML which automatically builds a plain text version if needed.
// Everything below is optional, even the $ezee_email_body_config variable
$ ezee_email_body_config = [
' word_wrap ' => 50 , // Defaults to 72, set 0 for no wrapping
' is_html ' => true , // Defaults to true
' template ' => "
<html>
<h2>New contact request</h2>
<div>
My name is $ name . I used to be a spy, until...
</div>
<br />
<div>
<b>Hey look, an email!</b> $ email
</div>
<br />
<div>
<b>This is a Message</b>
<p> $ message </p>
</div>
</html>
"
];
global $ ezee_email_vals ;
$ name = $ ezee_email_vals [ ' name ' ];
// Where email is sent from
$ ezee_email_send_from_config = [
' encryption_type ' => ' tls ' , // 'ssl' or 'tls'
' port ' => 587 ,
' server ' => ' smtp.gmail.com ' ,
' email ' => ' [email protected] ' ,
' password ' => ' xxxxxxxx ' // Password for address server
];
// Where email is sent to
$ ezee_email_send_to_config = [
// You can send the email to yourself
' addresses ' => ' [email protected] ' ,
' subject ' => " Contact from $ name " ,
];
// With both flags off, you don't have to set required_values
$ ezee_email_value_options = [
' limit_to_required ' => false ,
' fail_on_value_overload ' => false ,
];
// Uses default email body