PHPMailer\PHPMailer
PHPMailer::setFrom
Set the From and FromName properties.
Method of the class: PHPMailer{}
No Hooks.
Returns
true|false.
Usage
$PHPMailer = new PHPMailer(); $PHPMailer->setFrom( $address, $name, $auto );
- $address(string) (required)
- .
- $name(string)
- .
Default:'' - $auto(true|false)
- Whether to also set the Sender address, defaults to true.
Default:true
PHPMailer::setFrom() PHPMailer::setFrom code WP 7.0
public function setFrom($address, $name = '', $auto = true)
{
if (is_null($name)) {
//Helps avoid a deprecation warning in the preg_replace() below
$name = '';
}
$address = trim((string)$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)
|| ((!$this->has8bitChars(substr($address, ++$pos)) || !static::idnSupported())
&& !static::validateAddress($address))
) {
$error_message = sprintf(
'%s (From): %s',
self::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 && empty($this->Sender)) {
$this->Sender = $address;
}
return true;
}