public function PHPMailer::setFrom

5.x PHPMailer.php public PHPMailer::setFrom($address, $name = '', $auto = true)

Set the From and FromName properties.

Parameters

string $address:

string $name:

bool $auto Whether to also set the Sender address, defaults to true:

Return value

bool

Throws

Exception

File

inc/PHPMailer/src/PHPMailer.php, line 1183

Class

PHPMailer
PHPMailer - PHP email creation and transport class.

Namespace

PHPMailer\PHPMailer

Code

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().
  $pos = strrpos($address, '@');
  if (false === $pos or 
    (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) and 
    !static::validateAddress($address)) {
    $error_message = sprintf('%s (From): %s', 
    $this->lang('invalid_address'), 
    $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;
}