Antarmuka yang mudah digunakan untuk PHPMailer yang mengambil objek JSON dan mengirimkan nilainya melalui email, membalas dengan JSON
config.php
send-email.php
Ini adalah proyek yang sangat keras kepala. Jika mayoritas berpendapat bahwa perubahan akan bermanfaat, saya akan dengan senang hati mematuhinya. Jika tidak, jangan ragu untuk membuka PR atau menyampaikan ide.
'encryption_type'
tidak disetel, SMTPSecure
juga tidak akan disetelvalue
harus disetel ke sesuatu, meskipun hanya string kosong. Jika tidak, value
akan default ke null
, kondisi gagalincludes/create-default-email-body.php
Jika awal kunci JSON yang dikirimkan (dipisahkan dengan tanda hubung) cocok dengan salah satu string ini, format yang digunakan untuk memvalidasi/membersihkan nilai akan secara otomatis disetel ke format terkait yang ditampilkan di sini jika tidak ada 'format' yang diteruskan dalam larik JSON.
Contoh: Nilai pada kunci "phone-cell"
, "phone-home"
, dan "phone-intergalactic"
akan divalidasi/diurai sebagai nomor telepon, kecuali "format"-nya disetel secara eksplisit.
// 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 '
];
Jika tidak ada format yang dikirim, defaultnya adalah 'teks'. Anda dapat mengganti format default (lihat di atas) dengan mengirimkannya ke dalam array
{ // 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"
}
}
Semua balasan dalam JSON, dan (kebanyakan) mematuhi bentuk respons JSend. "status"
dari "gagal" (dengan data) atau "sukses" selalu mengembalikan data yang diterima tidak berubah di bawah kunci "raw"
, sedangkan status "gagal" menetapkan alasan mengapa kunci gagal di bawah "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)"
}
}
}
-- ATAU --
{ // 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