12. Beyond HTML
Introduction to QEmailServer
<< Previous   |   Back to Main   |   * Introduction to QRssFeed >>

View Source
will open in a new window
Emailing via SMTP
The QEmailServer class can be used to send email messages via any accessible SMTP server. Obviously, many PHP developers will be familiar with the PHP mail() function, which internally makes a shell call to sendmail. But note that for many reasons (including security, maintenance and deployability), QEmailServer does not use PHP's mail() nor does it use sendmail.

QEmailServer is an abstract class which only has static variables (which define the location of the SMTP server and other preferences) and a single static Send method. The Send method takes in a QEmailMessage object.

The QEmailMessage object contains the relavent email addresses (e.g. From, To, Cc and Bcc), as well as the subject and body. Note that the body can be in either plain text, HTML or both. Qcodo will automatically handle the multipart message encoding for you.

Finally, note that for development environments that do not have ready access to an SMTP server, the QEmailServer can be set to TestMode, where communication between the application and the SMTP server will be written to disk instead of an SMTP socket. This allows developers to develop and test email capability without actually sending out any emails.

Feel free to View Source the code. Note that the final Send call is commented out, so this page is actually non-functional. But you can view the code to get a sense as to how the QEmailServer and its associated QEmailMessage class work.
For obvious reasons, this page is non-functional. To view the commented out source, please click on View Source at the top right of the page.