PHPMailer::setFrom PHP Method

setFrom() public method

Set the From and FromName properties.
public setFrom ( string $address, string $name = '', boolean $auto = true ) : boolean
$address string
$name string
$auto boolean Whether to also set the Sender address, defaults to true
return boolean
    public function setFrom($address, $name = '', $auto = true)
    {
        $address = trim($address);
        $name = trim(preg_replace('/[\\r\\n]+/', '', $name));
        //Strip breaks and trim
        // Don't validate now addresses with IDN. Will be done in send().
        if (($pos = strrpos($address, '@')) === false or (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and !$this->validateAddress($address)) {
            $error_message = $this->lang('invalid_address') . " (setFrom) {$address}";
            $this->setError($error_message);
            $this->edebug($error_message);
            if ($this->exceptions) {
                throw new phpmailerException($error_message);
            }
            return false;
        }
        $this->From = $address;
        $this->FromName = $name;
        if ($auto) {
            if (empty($this->Sender)) {
                $this->Sender = $address;
            }
        }
        return true;
    }

Usage Example

        /**
         * Send email
         * @param 			array $to
         * @param 			array $from
         * @param 			string $subject
         * @param 			string $text
         * @param 			bool $use_template
         * @return 			bool
         */
        public function send($to, $from, $subject, $text, $use_template = true)
        {
            $this->client->setFrom($from[1], $from[0]);
            $this->client->addAddress($to[1], $to[0]);
            $this->client->Subject = $subject;
            if ($use_template) {
                $template = '
			<!DOCTYPE HTML>
			<html dir="rtl">
				<head>
					<meta charset="utf-8">
				</head>
				<body style="font-family: tahoma, sans-serif !important;">
					<div style="font: 13px tahoma,sans-serif !important;direction: rtl;background-color: #e8e8e8;">
						<div style="width: 70%;background-color: #fff;background-color: #fff; border-radius: 3px;margin: auto;position: relative;border-left: 1px solid #d9d9d9;border-right: 1px solid #d9d9d9;">
							<div style="top: 0;position: absolute;width: 100%; height: 4px;background: url( \'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAECAYAAAD8kH0gAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGhJREFUeNpi/P///xkGKFh27TfDkiu/GQiBKC1WhhgdVoLqXkzsZHje30ZQnUR+OYNkYRVWORZkxy0DOo6JgGERpDhuYgcDAxN+EyVyS3E6DgSYkB3HQG3HEQo5Ao4DO3AwOw4EAAIMAMZJM9nl1EbWAAAAAElFTkSuQmCC\' ) repeat;"></div>
							<div style="padding: 22px 15px;">
								{TEXT}
							</div>
							<div style="bottom: 0;position: absolute;width: 100%; height: 4px;background: url( \'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAECAYAAAD8kH0gAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGhJREFUeNpi/P///xkGKFh27TfDkiu/GQiBKC1WhhgdVoLqXkzsZHje30ZQnUR+OYNkYRVWORZkxy0DOo6JgGERpDhuYgcDAxN+EyVyS3E6DgSYkB3HQG3HEQo5Ao4DO3AwOw4EAAIMAMZJM9nl1EbWAAAAAElFTkSuQmCC\' ) repeat;"></div>
						</div>
					</div>
				</body>
			</html>
			';
                $msg = str_replace('{TEXT}', $text, $template);
            } else {
                $msg = $text;
            }
            $this->client->msgHTML($msg);
            return $this->client->send();
        }
All Usage Examples Of PHPMailer::setFrom