[php] Valeriu Dodon - Good Looking PHP Code Example

Viewer

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

Editor

You can edit this paste and save as new:


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