CMS  Version 3.9
SMTPEmailTransport Class Reference
+ Inheritance diagram for SMTPEmailTransport:
+ Collaboration diagram for SMTPEmailTransport:

Public Member Functions

 __construct ()
 
 send ()
 
 writeAttachment ($filename, $attachment)
 
- Public Member Functions inherited from AbstractEmailTransport
 setTo ($to)
 
 setSubject ($subject)
 
 setHTMLMessage ($message)
 
 setPlainMessage ($message)
 
 setFrom ($email, $name="")
 
 setReplyTo ($email, $name)
 
 setReturnPath ($path)
 
 addAttachment ($filename, $attachment)
 
 setICalAttachment ($ical, $method)
 

Additional Inherited Members

- Public Attributes inherited from AbstractEmailTransport
 $to = null
 
 $subject = "No Subject"
 
 $htmlMessage = ""
 
 $plainMessage = ""
 
 $emailFrom = ""
 
 $emailName = ""
 
 $replyTo = ""
 
 $replyToName = ""
 
 $returnPath = ""
 
 $attachments = array()
 
 $ical = null
 
 $icalMethod = null
 

Detailed Description

Definition at line 80 of file email_manager.inc.

Constructor & Destructor Documentation

◆ __construct()

SMTPEmailTransport::__construct ( )

Definition at line 82 of file email_manager.inc.

83  {
84  }

Member Function Documentation

◆ send()

SMTPEmailTransport::send ( )

Reimplemented from AbstractEmailTransport.

Definition at line 86 of file email_manager.inc.

87  {
88  $site_email_from = Settings::getValue('email', 'email_from');
89 
90  $returnPath = $this->returnPath ? $this->returnPath : $this->emailFrom;
91  $replyTo = $this->replyTo ? "{$this->replyName} <{$this->replyTo}>" : "{$this->emailName} <{$this->emailFrom}>";
92  // Use the MD5 algorithm to generate a random hash
93  $from = $this->emailName . " <" . $this->emailFrom . ">";
94 
95  $headers = "Return-Path: ". $returnPath . "\r\n";
96  $headers .= "Reply-To: ". $replyTo ."\r\n";
97  $headers .= "MIME-Version: 1.0\r\n";
98 
99  $random_hash = md5(date('r', time()));
100 
101  $headers .= "Content-Type: multipart/alternative; boundary=\"--PHP-alt-".$random_hash."\"\r\n";
102 
103  $message = "";
104 
105  if (!$this->plainMessage) $this->plainMessage = HTMLToText($this->htmlMessage);
106 
107  $message .= <<<ENDMESSAGE
108 ----PHP-alt-{$random_hash}
109 Content-Type: text/plain
110 Content-Disposition: inline
111 Content-Transfer-Encoding: 8bit
112 
113 {$this->plainMessage}
114 
115 
116 ----PHP-alt-{$random_hash}
117 Content-Type: text/html
118 Content-Disposition: inline
119 Content-Transfer-Encoding: 8bit
120 
121 {$this->htmlMessage}
122 ENDMESSAGE;
123 
124  foreach($this->attachments as $filename => $attachment)
125  {
126  $message .= "----PHP-alt-{$random_hash}\r\n";
128  }
129 
130  if ($this->ical)
131  {
132  $message .= <<<ENDMESSAGE
133 ----PHP-alt-{$random_hash}
134 Content-Type: text/calendar; charset=utf-8;method={$this->icalMethod}
135 Content-Disposition: inline; filename=meeting.ics
136 Content-Transfer-Encoding: 8bit
137 
138 ENDMESSAGE;
139  }
140 
141  trace("Sending Mail from {$from} to {$this->to}: {$this->subject}", 3);
142  $this->mail = new Mail($site_email_from, $this->to, $this->subject, $message, $headers, $from);
143 
144  $rtn = $this->mail->send();
145 
146  return $rtn;
147  }
if(! $attachment_id) $attachment
Definition: delete.inc:42
$attachment filename
Definition: upload.inc:87
Definition: mail.inc:40
writeAttachment($filename, $attachment)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$forumRequest to
$message
Definition: mail_to.inc:49
$email subject
if(!Settings::getValue("debug", "enable_trace_file_downloads")) $filename
Definition: trace.inc:42

◆ writeAttachment()

SMTPEmailTransport::writeAttachment (   $filename,
  $attachment 
)

Definition at line 149 of file email_manager.inc.

150  {
151  $fileAttachments = "";
152  if(is_file($attachment))
153  {
154  $base_filename = basename($attachment);
155 
156  $fileAttachments .= "----PHP-alt-{$random_hash}\n";
157  $fp = @fopen($attachment, "rb");
158  $fileContents = @fread($fp, filesize($attachment));
159  @fclose($fp);
160  $fileContents = chunk_split(base64_encode($fileContents));
161  $fileAttachments .= "Content-Type: application/octet-stream; name=\"". $base_filename ."\"\n" .
162  "Content-Description: ".$base_filename."\n" .
163  "Content-Disposition: attachment;\n" . " filename=\"". $base_filename ."\"; size=".filesize($attachment).";\n" .
164  "Content-Transfer-Encoding: base64\n\n" . $fileContents . "\n\n";
165  }
166 
167  return $fileAttachments;
168  }

The documentation for this class was generated from the following file: