LLMS_Email::add_recipient( int|string $address, string $type = 'to', string $name = '' )

Add a single recipient for sending to, cc, or bcc


Parameters Parameters

$address

(int|string) (Required) if string, must be a valid email address if int, must be the WP User ID of a user

$type

(string) (Optional) recipient type [to,cc,bcc]

Default value: 'to'

$name

(string) (Optional) recipient name (optional)

Default value: ''


Top ↑

Return Return

(boolean)


Top ↑

Source Source

File: includes/emails/class.llms.email.php

	public function add_recipient( $address, $type = 'to', $name = '' ) {

		// If an ID was supplied, get the information from the student object.
		if ( is_numeric( $address ) ) {
			$student = llms_get_student( $address );
			if ( ! $student ) {
				return false;
			}
			$address = $student->get( 'user_email' );
			$name    = $student->get_name();
		}

		// Ensure address is a valid email.
		if ( ! filter_var( $address, FILTER_VALIDATE_EMAIL ) ) {
			return false;
		}

		// If a name is supplied format the name & address.
		if ( $name ) {
			$address = sprintf( '%1$s <%2$s>', $name, $address );
		}

		if ( 'to' === $type ) {

			array_push( $this->recipient, $address );
			return true;

		} elseif ( 'cc' === $type || 'bcc' === $type ) {

			$this->add_header( ucfirst( $type ), $address );
			return true;

		}

		return false;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.