PHPMailer\PHPMailer\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 Exception($error_message);
            }
            return false;
        }
        $this->From = $address;
        $this->FromName = $name;
        if ($auto) {
            if (empty($this->Sender)) {
                $this->Sender = $address;
            }
        }
        return true;
    }

Usage Example

 private function setOptions()
 {
     $this->mailClient->isSMTP();
     $this->mailClient->SMTPAuth = true;
     $this->mailClient->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $this->mailClient->addAddress($this->options->getFrom());
     $this->mailClient->Host = $this->options->getHost();
     $this->mailClient->Username = $this->options->getUserName();
     $this->mailClient->Password = $this->options->getPassword();
     $this->mailClient->setFrom($this->options->getFrom());
     $this->mailClient->Port = $this->options->getPort();
     $this->addCCs();
 }
All Usage Examples Of PHPMailer\PHPMailer\PHPMailer::setFrom