Automator_Email_Helpers::headers( array $header_data = array() )


Parameters Parameters

$header_data

(array) (Optional)

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/helpers/class-automator-email-helpers.php

	public function headers( $header_data = array() ) {

		/**
		 * @param string $from
		 * @param string $from_name
		 * @param array $cc
		 * @param array $bcc
		 * @param string $reply_to
		 * @param string $content
		 * @param string $charset
		 */
		extract( $header_data ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
		$headers = array();

		// Add From in headers.
		if ( ! empty( $from_name ) && ! empty( $from ) ) {
			$headers[] = 'From: ' . $from_name . ' <' . $from . '>';
		} elseif ( ! empty( $from ) ) {
			$headers[] = 'From: <' . $from . '>';
		}

		// Add CC in headers.
		if ( ! empty( $cc ) ) {
			$cced      = join( ', ', $cc );
			$headers[] = "CC: $cced";
		}

		// Add BCC in headers.
		if ( ! empty( $bcc ) ) {
			$bcced     = join( ', ', $bcc );
			$headers[] = "BCC: $bcced";
		}

		// Add Reply-to in headers.
		if ( ! empty( $reply_to ) ) {
			$headers[] = "Reply-To: $reply_to";
		}

		// Add Content-type and charset in headers.
		if ( ! empty( $content ) ) {
			$type = 'Content-Type: ' . $content . ';';
			if ( ! empty( $charset ) ) {
				$type .= ' charset=' . $charset . ';';
			}
			$headers[] = $type;
		}

		return $headers;
	}