| Server IP : 43.130.17.34 / Your IP : 216.73.217.6 Web Server : nginx/1.28.0 System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,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,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/yespkg.com/wp-content/plugins/elementor-pro/core/integrations/actions/email/ |
Upload File : |
<?php
namespace ElementorPro\Core\Integrations\Actions\Email;
use ElementorPro\Core\Integrations\Actions\Action_Base;
use ElementorPro\Core\Integrations\Exceptions\Action_Failed_Exception;
use ElementorPro\Core\Integrations\Exceptions\Action_Validation_Failed_Exception;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Email extends Action_Base {
/**
* @param Email_Message $payload
*
* @return void
* @throws \Exception
*/
public function apply( $payload ) {
// Set default headers.
$headers = [
sprintf( 'Content-Type: %s; charset=UTF-8', $payload->content_type ),
sprintf( 'From: %s', $payload->from->format() ),
];
foreach ( $payload->reply_to as $recipient ) {
$headers[] = sprintf( 'Reply-To: %s', $recipient->format() );
}
// Set CC headers.
$cc_headers = [];
foreach ( $payload->cc as $recipient ) {
$cc_headers[] = sprintf( 'Cc: %s', $recipient->format() );
}
// Send email.
$this->send_mail(
$payload->to->format(),
$payload->subject,
$payload->body,
implode( PHP_EOL, array_merge( $headers, $cc_headers ) ),
$payload->attachments
);
// Send BCC emails.
foreach ( $payload->bcc as $bcc ) {
$this->send_mail(
$bcc->format(),
$payload->subject,
$payload->body,
implode( PHP_EOL, $headers ),
$payload->attachments
);
}
}
/**
* @alias `$this->run()`
*
* @param Email_Message $payload
*
* @return void
*@throws \Exception
*
*/
public function send( Email_Message $payload ) {
$this->run( $payload );
}
/**
* Validate the email message DTO.
*
* @param Email_Message $payload
*
* @throws \ElementorPro\Core\Integrations\Exceptions\Action_Validation_Failed_Exception
*
* @return void
*/
public function validate( $payload ) {
$required_fields = [
'from',
'to',
'subject',
'body',
'content_type',
];
foreach ( $required_fields as $field ) {
if ( empty( $payload->{$field} ) ) {
throw new Action_Validation_Failed_Exception(
static::class,
"`Email_Message::\${$field}` is required."
);
}
}
}
/**
* Calls `wp_mail()`. Used for testing.
*
* @param mixed ...$args
*
* @return void
*/
protected function send_mail( ...$args ) {
add_action( 'wp_mail_failed', [ $this, 'on_wp_mail_error' ] );
wp_mail( ...$args );
remove_action( 'wp_mail_failed', [ $this, 'on_wp_mail_error' ] );
}
/**
* Throw exception on `wp_mail()` error.
*
* @param \WP_Error $error
*
* @throws \ElementorPro\Core\Integrations\Exceptions\Action_Failed_Exception
*
* @return void
*/
public function on_wp_mail_error( \WP_Error $error ) {
throw new Action_Failed_Exception( static::class, '`wp_mail()` cannot send email', $error );
}
}