[php] Good Looking PHP Code Example

Viewer

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

Editor

You can edit this paste and save as new:


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