| Server IP : 89.108.64.180 / Your IP : 216.73.217.92 Web Server : Apache/2.4.41 (Ubuntu) System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-root ( 1010) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/poseidon-gagra.ru/wp-content/plugins/awebooking/inc/Email/ |
Upload File : |
<?php
namespace AweBooking\Email;
class Message {
/**
* Email addresses to send message.
*
* @var string|array
*/
public $to;
/**
* Email subject.
*
* @var string
*/
public $subject;
/**
* Email content.
*
* @var string
*/
public $content;
/**
* Additional headers.
*
* @var string
*/
public $headers;
/**
* Files to attach.
*
* @var string|array
*/
public $attachments;
/**
* Send HTML emails from AweBooking using wp_mail().
*
* @param string|array $to Array or comma-separated list of email addresses to send message.
* @param string $subject Email subject.
* @param string $content Email content.
* @param string|array $headers Optional. Additional headers.
* @param string|array $attachments Optional. Files to attach.
*/
public function __construct( $to, $subject = null, $content = '', $headers = "Content-Type: text/html\r\n", $attachments = [] ) {
$this->to = $to;
$this->subject = $subject;
$this->content = $content;
$this->headers = $headers;
$this->attachments = $attachments;
}
/**
* Sets the email content.
*
* @param string $content Email content.
* @return $this
*/
public function content( $content ) {
$this->content = $content;
return $this;
}
/**
* Sets the email subject.
*
* @param string $subject Email subject.
* @return $this
*/
public function subject( $subject ) {
$this->subject = $subject;
return $this;
}
/**
* Sets the email headers.
*
* @param string|array $headers Email headers.
* @return $this
*/
public function headers( $headers ) {
$this->headers = $headers;
return $this;
}
/**
* Sets the email attachments.
*
* @param string|array $attachments Email attachments.
* @return $this
*/
public function attachments( $attachments ) {
$this->attachments = $attachments;
return $this;
}
/**
* Send the message.
*
* @return bool
*/
public function send() {
$to = is_string( $this->to ) ? array_map( 'trim', explode( ',', $this->to ) ) : $this->to;
$to = array_unique( array_filter( $to, 'is_email' ) );
if ( empty( $to ) ) {
return false;
}
add_filter( 'wp_mail_from', [ $this, 'get_from_address' ] );
add_filter( 'wp_mail_from_name', [ $this, 'get_from_name' ] );
$sended = abrs_rescue( function () use ( $to ) {
return wp_mail( $to, $this->subject, $this->content, $this->headers, $this->attachments );
}, false );
remove_filter( 'wp_mail_from', [ $this, 'get_from_address' ] );
remove_filter( 'wp_mail_from_name', [ $this, 'get_from_name' ] );
return $sended;
}
/**
* Get the "from name" for outgoing emails.
*
* @param string $from_name Name associated with the "from" email address.
* @return string
*/
public function get_from_name( $from_name ) {
$name = apply_filters( 'abrs_email_from_name', abrs_get_option( 'email_from_name' ), $this );
return $name ? wp_specialchars_decode( esc_html( $name ), ENT_QUOTES ) : $from_name;
}
/**
* Get the "from address" for outgoing emails.
*
* @param string $from_email Email address to send from.
* @return string
*/
public function get_from_address( $from_email ) {
$from_address = apply_filters( 'abrs_email_from_address', abrs_get_option( 'email_from_address' ), $this );
return $from_address ? sanitize_email( $from_address ) : $from_email;
}
}