[php] Good Looking PHP Code Example
Viewer
- <?php
- namespace Email;
- class Client
- {
- public function send(string $emailAddress, Message $message): bool
- {
- if (!$this->validateParameters($emailAddress, $message)) {
- return false;
- }
- return $this->sendToMailServer([
- 'to' => $emailAddress,
- 'text' => $message->text(),
- ]);
- }
- private function validateParameters(string $emailAddress, Message $message): bool
- {
- $validateEmail = filter_var($emailAddress, FILTER_VALIDATE_EMAIL);
- $validateMessage = strlen($message->text()) < 1000;
- if (!$validateEmail || !$validateMessage) {
- return false;
- }
- return true;
- }
- private function sendToMailServer(array $params): bool
- {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://mail.example.com');
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
- $result = curl_exec($curl);
- curl_close($curl);
- return $result;
- }
- }
Editor
You can edit this paste and save as new: