Changeset 10 for Common/Mail.php
- Timestamp:
- Apr 7, 2020, 8:52:35 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/Mail.php
r8 r10 69 69 function Organization($org) 70 70 { 71 if (trim($org != '')) $this->xheaders['Organization'] = $org;71 if (trim($org != '')) $this->xheaders['Organization'] = $org; 72 72 } 73 73 74 74 function Priority($Priority) 75 75 { 76 if (!intval($Priority)) return(false);77 78 if (!isset($this->priorities[$Priority - 1])) return(false);76 if (!intval($Priority)) return false; 77 78 if (!isset($this->priorities[$Priority - 1])) return false; 79 79 80 80 $this->xheaders['X-Priority'] = $this->priorities[$Priority - 1]; 81 return (true);81 return true; 82 82 } 83 83 … … 96 96 function Send() 97 97 { 98 if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body'));98 if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body')); 99 99 100 100 $Body = $this->BuildAttachment($this->BuildBody()); … … 103 103 $this->Headers['CC'] = ''; 104 104 $this->Headers['BCC'] = ''; 105 foreach ($this->Recipients as $Index => $Recipient)106 { 107 if ($Recipient['Type'] == 'SendCombined')108 { 109 if ($Index > 0) $To .= ', ';105 foreach ($this->Recipients as $Index => $Recipient) 106 { 107 if ($Recipient['Type'] == 'SendCombined') 108 { 109 if ($Index > 0) $To .= ', '; 110 110 $To .= $Recipient['Address']; 111 111 } else 112 if ($Recipient['Type'] == 'Send')113 { 114 if ($Index > 0) $To .= ', ';112 if ($Recipient['Type'] == 'Send') 113 { 114 if ($Index > 0) $To .= ', '; 115 115 $To .= $Recipient['Name'].' <'.$Recipient['Address'].'>'; 116 116 } else 117 if ($Recipient['Type'] == 'Copy')118 { 119 if ($Index > 0) $this->Headers['CC'] .= ', ';117 if ($Recipient['Type'] == 'Copy') 118 { 119 if ($Index > 0) $this->Headers['CC'] .= ', '; 120 120 $this->Headers['CC'] .= $Recipient['Name'].' <'.$To['Address'].'>'; 121 121 } else 122 if ($Recipient['Type'] == 'HiddenCopy')123 { 124 if ($Index > 0) $this->Headers['BCC'] .= ', ';122 if ($Recipient['Type'] == 'HiddenCopy') 123 { 124 if ($Index > 0) $this->Headers['BCC'] .= ', '; 125 125 $this->Headers['BCC'] .= $Recipient['Name'].' <'.$To['Address'].'>'; 126 126 } 127 127 } 128 if ($To == '') throw new Exception(T('Mail message need at least one recipient address'));128 if ($To == '') throw new Exception(T('Mail message need at least one recipient address')); 129 129 130 130 $this->Headers['Mime-Version'] = '1.0'; 131 131 132 if ($this->AgentIdent != '') $this->Headers['X-Mailer'] = $this->AgentIdent;133 if ($this->ReplyTo != '') $this->Headers['Reply-To'] = $this->ReplyTo;134 if ($this->From != '') $this->Headers['From'] = $this->From;132 if ($this->AgentIdent != '') $this->Headers['X-Mailer'] = $this->AgentIdent; 133 if ($this->ReplyTo != '') $this->Headers['Reply-To'] = $this->ReplyTo; 134 if ($this->From != '') $this->Headers['From'] = $this->From; 135 135 136 136 $Headers = ''; 137 foreach ($this->Headers as $Header => $Value)138 { 139 if (($Header != 'Subject') and ($Value != '')) $Headers .= $Header.': '.$Value."\n";137 foreach ($this->Headers as $Header => $Value) 138 { 139 if (($Header != 'Subject') and ($Value != '')) $Headers .= $Header.': '.$Value."\n"; 140 140 } 141 141 142 142 $this->Subject = strtr($this->Subject, "\r\n", ' '); 143 143 144 if ($this->Subject == '') throw new Exception(T('Mail message missing Subject'));144 if ($this->Subject == '') throw new Exception(T('Mail message missing Subject')); 145 145 146 146 147 147 $res = mail($To, $this->Subject, $Body, $Headers); 148 return ($res);148 return $res; 149 149 } 150 150 151 151 function ValidEmail($Address) 152 152 { 153 if (ereg(".*<(.+)>", $Address, $regs)) $Address = $regs[1];154 if (ereg("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))155 return (true);156 else return (false);153 if (ereg(".*<(.+)>", $Address, $regs)) $Address = $regs[1]; 154 if (ereg("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address)) 155 return true; 156 else return false; 157 157 } 158 158 159 159 function CheckAdresses($Addresses) 160 160 { 161 foreach ($Addresses as $Address)162 { 163 if (!$this->ValidEmail($Address))161 foreach ($Addresses as $Address) 162 { 163 if (!$this->ValidEmail($Address)) 164 164 throw new Exception(sprintf(T('Mail message invalid address %s'), $Address)); 165 165 } … … 168 168 private function ContentEncoding($Charset) 169 169 { 170 if ($Charset != CHARSET_ASCII) return('8bit');171 else return ('7bit');170 if ($Charset != CHARSET_ASCII) return '8bit'; 171 else return '7bit'; 172 172 } 173 173 174 174 private function BuildAttachment($Body) 175 175 { 176 if (count($this->Attachments) > 0)176 if (count($this->Attachments) > 0) 177 177 { 178 178 $this->Headers['Content-Type'] = "multipart/mixed;\n boundary=\"PHP-mixed-".$this->Boundary."\""; … … 181 181 $Result .= $Body; 182 182 183 foreach ($this->Attachments as $Attachment)183 foreach ($this->Attachments as $Attachment) 184 184 { 185 185 $FileName = $Attachment['FileName']; … … 187 187 $ContentType = $Attachment['FileType']; 188 188 $Disposition = $Attachment['Disposition']; 189 if ($Attachment['Type'] == 'File')189 if ($Attachment['Type'] == 'File') 190 190 { 191 if (!file_exists($FileName))191 if (!file_exists($FileName)) 192 192 throw new Exception(sprintf(T('Mail message attached file %s can\'t be found'), $FileName)); 193 193 $Data = file_get_contents($FileName); 194 194 } else 195 if ($Attachment['Type'] == 'Data') $Data = $Attachment['Data'];195 if ($Attachment['Type'] == 'Data') $Data = $Attachment['Data']; 196 196 else $Data = ''; 197 197 … … 203 203 } 204 204 } else $Result = $Body; 205 return ($Result);205 return $Result; 206 206 } 207 207 … … 209 209 { 210 210 $Result = ''; 211 if (count($this->Bodies) > 1)211 if (count($this->Bodies) > 1) 212 212 { 213 213 $this->Headers['Content-Type'] = 'multipart/alternative; boundary="PHP-alt-'.$this->Boundary.'"'; … … 221 221 222 222 223 foreach ($this->Bodies as $Body)224 { 225 if (count($this->Bodies) > 1) $Result .= "\n\n".'--PHP-alt-'.$this->Boundary."\n";223 foreach ($this->Bodies as $Body) 224 { 225 if (count($this->Bodies) > 1) $Result .= "\n\n".'--PHP-alt-'.$this->Boundary."\n"; 226 226 $Result .= 'Content-Type: '.$Body['Type'].'; charset='.$Body['Charset']. 227 227 "\nContent-Transfer-Encoding: ".$this->ContentEncoding($Body['Charset'])."\n\n".$Body['Content']."\n"; 228 228 } 229 return ($Result);229 return $Result; 230 230 } 231 231 }
Note:
See TracChangeset
for help on using the changeset viewer.