92 private function stringToAddress($str)
97 $addresses = $parser->parse($str);
103 private function isAddress($obj)
114 if ($this->isAddress($address)) {
115 $this->from = $address;
116 } elseif (is_scalar($address)) {
117 $addr = $this->stringToAddress($address);
118 if (count($addr) > 0) {
119 $this->from = $addr[0];
130 if ($this->isAddress($address)) {
131 $this->sender = $address;
132 } elseif (is_scalar($address)) {
133 $addr = $this->stringToAddress($address);
134 if (count($addr) > 0) {
135 $this->sender = $addr[0];
176 foreach ($tAddresses as
$to) {
177 if (is_a($to,
'Dcp\\Mail\\Address') && $to->address) {
179 $tos[] = sprintf(
'"%s" <%s>', str_replace(
'"',
' ', $to->name), $to->address);
181 $tos[] =$to->address;
185 return implode(
",", $tos);
195 if ($this->isAddress($address)) {
196 $this->to[] = $address;
197 } elseif (is_scalar($address)) {
198 foreach ($this->stringToAddress($address) as $addr) {
217 if ($this->isAddress($address)) {
218 $this->cc[] = $address;
219 } elseif (is_scalar($address)) {
220 foreach ($this->stringToAddress($address) as $addr) {
239 if ($this->isAddress($address)) {
240 $this->bcc[] = $address;
241 } elseif (is_scalar($address)) {
242 foreach ($this->stringToAddress($address) as $addr) {
243 $this->bcc[] = $addr;
252 $this->bcc = array();
279 $this->bodyRelated[] = $attachment;
286 $this->bodyRelated = array();
295 $this->altBody =
$body;
304 $this->attachments[] = $attachment;
311 $this->attachments = array();
320 return $this->_sendWithPHPMailer();
322 private function _sendWithPHPMailer()
324 include_once (
"WHAT/Lib.Common.php");
326 $mail = new \PHPMailer();
338 $mail->SMTPAutoTLS =
false;
345 $mail->setLanguage($lcConfig[
'locale']);
347 $host =
getParam(
'SMTP_HOST',
'localhost');
353 $mail->SMTPAuth =
true;
354 $password =
getParam(
'SMTP_PASSWORD');
356 $mail->Password = $password;
358 if (!isset($this->sender)) {
361 $parsedMail = $this->stringToAddress(
$sender);
362 if (count($parsedMail) > 0) {
364 if (isset($this->from)) {
366 $mail->addCustomHeader(
'Sender', $this->from->address);
368 $mail->addReplyTo($this->from->address, $this->from->name);
382 $this->
setFrom(
new Address(
$sender->address, sprintf(
"%s via %s", $this->from->name,
$sender->name)));
387 if (isset($this->sender)) {
389 $mail->Sender = $this->sender->address;
391 if (isset($this->from)) {
392 $mail->From = $this->from->address;
393 $mail->FromName = $this->from->name;
395 foreach ($this->to as
$to) {
396 $mail->addAddress($to->address, $to->name);
398 foreach ($this->cc as $to) {
399 $mail->addCC($to->address, $to->name);
401 foreach ($this->bcc as $to) {
402 $mail->addBCC($to->address, $to->name);
404 $mail->CharSet =
"UTF-8";
406 $mail->MessageID =
'<' . strftime(
"%Y%M%d%H%M%S-", time()) . rand(1, 65535) .
"@%s>";
407 $mail->MessageID = sprintf(
'<%s%s@%s>', strftime(
"%Y%M%d%H%M%S-", time()) , rand(1, 65535) , $host);
409 $mail->AllowEmpty =
true;
410 if (isset($this->body)) {
411 if ($this->body->type ==
'text/html') {
414 $mail->Body = $this->body->data;
416 foreach ($this->bodyRelated as $attachment) {
417 $mail->addEmbeddedImage($attachment->file, $attachment->cid, $attachment->name,
'base64', $attachment->type);
419 if (isset($this->altBody)) {
420 $mail->AltBody = $this->altBody->data;
422 foreach ($this->attachments as $attachment) {
423 $mail->addAttachment($attachment->file, $attachment->name,
'base64', $attachment->type);
425 $ret = $mail->send();
426 if (
$ret ===
false) {
427 return $mail->ErrorInfo;
static getParameterValue($application, $parameterName)
addressesToString(array $tAddresses)
getLocaleConfig($core_lang= '')
addBodyRelatedAttachment(RelatedAttachment &$attachment)
resetBodyRelatedAttachment()
getParam($name, $def="")
must be in core or global type
addAttachment(Attachment &$attachment)