[php] Valeriu Dodon - Good Looking PHP Code Example
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- namespace Email;
- /**
- * Email Client
- *
- *
- * @author Valeriu Dodon <[email protected]>
- * @since 1.0.0
- */
- class Email_Client {
- const VERSION = '1.0.0';
- /**
- *
- * Send an email
- *
- * @param string $emailAddress Email Addres
- * @param string $message Message Content
- * @return boolean
- *
- * @since 1.0.0
- */
- public function send_email(string $emailAddress, Message $message): bool {
- if (!$this->validateTheParameters($emailAddress, $message)) {
- return false;
- }
- return $this->sendEmailToServer([
- 'to' => $emailAddress,
- 'text' => $message->text(),
- ]);
- }
- /**
- *
- * Validate parameters
- *
- * @param string $emailAddress Email Addres
- * @param string $message Message Content
- * @return boolean
- *
- * @since 1.0.0
- */
- private function validateTheParameters(string $emailAddress, Message $message): bool {
- $validateEmail = filter_var($emailAddress, FILTER_VALIDATE_EMAIL);
- # TODO: To validate the message string length
- return true;
- }
- /**
- *
- * Send to Mail Server
- *
- * @param array $params Parameters array data
- * @return boolean
- *
- * @since 1.0.0
- */
- private function sendEmailToServer(array $params): bool {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'https://mail.google.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: