phpmailer = $phpmailer; $this->request = $request; } /** * Check for property/method in $phpmailer. * * @param String $name * * @return String */ public function __get( $name ) { if ( property_exists( $this->phpmailer, $name ) ) { return $this->phpmailer->$name; } return ''; } /** * Caller method * * @param String $name * @param Array $arguments * * @return Self|Null */ public function __call( $name, $arguments ) { if ( method_exists( $this->phpmailer, $name ) ) { return call_user_func( array( $this->phpmailer, $name ), $arguments ); } return null; } /** * Get attachments * * @return Array */ public function get_attachments() { $attachments = $this->phpmailer->get_attachments(); $attachments = array_map( array( $this, 'formatAttachment' ), $attachments ); return $attachments; } /** * Send email * * @return Bool */ public function send() { $to_emails = array_map( array( $this, 'formatEmails' ), $this->getToAddresses() ); $cc_emails = array_map( array( $this, 'formatEmails' ), $this->getCcAddresses() ); $bcc_emails = array_map( array( $this, 'formatEmails' ), $this->getBccAddresses() ); $args = array( 'body' => array( 'to' => json_encode( (array) $to_emails ), 'from' => $this->From, // @codingStandardsIgnoreLine 'from_name' => $this->FromName, // @codingStandardsIgnoreLine 'subject' => $this->Subject, // @codingStandardsIgnoreLine ), ); if ( 'text/html' === $this->ContentType ) { // @codingStandardsIgnoreLine $args['body']['body'] = $this->Body; // @codingStandardsIgnoreLine $args['body']['altbody'] = $this->AltBody; // @codingStandardsIgnoreLine } else { $args['body']['altbody'] = $this->Body; // @codingStandardsIgnoreLine } if ( $reply_to = $this->getReplyToAddresses() ) { // @codingStandardsIgnoreLine /** * $reply_to is an array of arrays. * [ [ $address, $name ], [...] ] * To get a string value for the address, we need to reset it twice. */ $reply_to = reset( $reply_to ); $args['body']['reply_to'] = reset( $reply_to ); } if ( ! empty( $cc_emails ) ) { $args['body']['cc'] = json_encode( (array) $cc_emails ); } if ( ! empty( $bcc_emails ) ) { $args['body']['bcc'] = json_encode( (array) $bcc_emails ); } $attachments = $this->get_attachments(); if ( $attachments ) { $args['body']['attachments'] = $attachments; } // Response is empty... $response = $this->request->post( $args ); return true; // Sent by the Service. } /** * Format email addresses * * @param Array $emails * * @return Array */ protected function formatEmails( $emails ) { return reset( $emails ); } /** * Format attachments * * @param Array $attachments * * @return Array */ protected function formatAttachment( $attachment ) { return array( 'filename' => $attachment[1], // $filename per PHPMailer docs. 'filedata' => file_get_contents( $attachment[0] ), // $path per PHPMailer docs. ); } }