Changeset 15 for Common/Mail.php


Ignore:
Timestamp:
Dec 27, 2022, 3:11:01 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Updates and fixes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/Mail.php

    r14 r15  
    2020  private array $Priorities;
    2121  private string $Boundary;
     22  public bool $TestMode;
    2223
    2324  function __construct()
     
    2627    $this->Boundary = md5(date('r', time()));
    2728    $this->AgentIdent = 'PHP/Mail';
     29    $this->TestMode = false;
    2830    $this->Clear();
    2931  }
     
    133135    if ($this->AgentIdent != '') $this->Headers['X-Mailer'] = $this->AgentIdent;
    134136    if ($this->ReplyTo != '') $this->Headers['Reply-To'] = $this->ReplyTo;
    135     if ($this->From != '') $this->Headers['From'] = $this->From;
     137    if ($this->From != '')
     138    {
     139      $IndexStart = strpos($this->From, '<');
     140      if ($IndexStart !== false)
     141      {
     142        $this->Headers['From'] = '=?utf-8?Q?'.quoted_printable_encode(trim(substr($this->From, 0, $IndexStart))).'?= '.substr($this->From, $IndexStart);
     143      } else
     144      {
     145        $this->Headers['From'] = $this->From;
     146      }
     147    }
    136148
    137149    $Headers = '';
     
    145157    if ($this->Subject == '') throw new Exception(T('Mail message missing Subject'));
    146158
    147     $res = mail($To, $this->Subject, $Body, $Headers);
     159    if ($this->TestMode)
     160    {
     161      echo('to: '.$To.', subject: '.$this->Subject.', body: '.$Body.', headers: '.$Headers);
     162      $res = true;
     163    } else
     164    {
     165      $res = mail($To, $this->Subject, $Body, $Headers);
     166    }
    148167    return $res;
    149168  }
Note: See TracChangeset for help on using the changeset viewer.