[php] Good Looking PHP Code Example

Viewer

copydownloadembedprintName: Good Looking PHP Code Example
  1. <?php
  2.  
  3. namespace Email;
  4.  
  5. /**
  6. * Email Client
  7. * @package    Email_Client
  8. * @author     Valeriu Dodon <[email protected]>
  9. **/
  10. class Email_Client {
  11.     /**
  12.     * 
  13.     * Send an email
  14.     *
  15.     * @param string $emailAddress   Email Addres
  16.     * @param string $message        Message Content
  17.     * @return boolean
  18.     **/
  19.     public function send_email(string $emailAddress, Message $message): bool {
  20.         if (!$this->validateParameters($emailAddress, $message)) {
  21.             return false;
  22.         }
  23.  
  24.         return $this->sendToMailServer([
  25.             'to' => $emailAddress,
  26.             'text' => $message->text(),
  27.         ]);
  28.     }
  29.  
  30.     /**
  31.     * 
  32.     * Validate parameters
  33.     *
  34.     * @param string $emailAddress   Email Addres
  35.     * @param string $message        Message Content
  36.     * @return boolean
  37.     **/
  38.     private function validateParameters(string $emailAddress, Message $message): bool
  39.     {
  40.         $validateEmail = filter_var($emailAddress, FILTER_VALIDATE_EMAIL);
  41.         # TODO: to validate the message string length
  42.  
  43.         return true;
  44.     }
  45.  
  46.     /**
  47.     * 
  48.     * Send to Mail Server
  49.     *
  50.     * @param array $params  Parameters array data
  51.     * @return boolean
  52.     **/
  53.     private function sendToMailServer(array $params): bool {
  54.         $curl = curl_init();
  55.         curl_setopt($curl, CURLOPT_URL, 'https://mail.google.com');
  56.         curl_setopt($curl, CURLOPT_POST, true);
  57.         curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
  58.  
  59.         $result = curl_exec($curl);
  60.         curl_close($curl);
  61.  
  62.         return $result;
  63.     }
  64. }

Editor

You can edit this paste and save as new:


File Description
  • Good Looking PHP Code Example
  • Paste Code
  • 23 May-2020
  • 1.59 Kb
You can Share it: