fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-mail / doc / book / intro.md
blob321977830c48e77ef5f1331a4f2204bb0f5029ef
1 # Introduction
3 zend-mail provides generalized functionality to compose and send both text and
4 MIME-compliant multipart email messages. Mail can be sent with zend-mail via any
5 of the Sendmail, SMTP, or file-based transports it defines.  You can also
6 implement your own transport by implementing the
7 `Zend\Mail\Transport\TransportInterface`.
9 ## Basic email
11 A basic email consists of one or more recipients, a subject, a body and a
12 sender. To send such a mail using `Zend\Mail\Transport\Sendmail`, do the
13 following:
15 ```php
16 use Zend\Mail;
18 $mail = new Mail\Message();
19 $mail->setBody('This is the text of the email.');
20 $mail->setFrom('Freeaqingme@example.org', "Sender's name");
21 $mail->addTo('Matthew@example.com', 'Name of recipient');
22 $mail->setSubject('TestSubject');
24 $transport = new Mail\Transport\Sendmail();
25 $transport->send($mail);
26 ```
28 > ### Minimum definitions
30 > In order to send an email using zend-mail you have to specify at least one
31 > recipient as well as a message body. Please note that each transport may
32 > require additional parameters to be set.
34 For most mail attributes there are "get" methods to read the information stored
35 in the message object. for further details, please refer to the API
36 documentation.
38 ## Configuring the default sendmail transport
40 The default transport is `Zend\Mail\Transport\Sendmail`. It is a wrapper to the
41 PHP [mail()](http://php.net/mail) function. If you wish to pass additional
42 parameters to the [mail()](http://php.net/mail) function, create a new transport
43 instance and pass your parameters to the constructor.
45 ### Passing additional mail() parameters
47 This example shows how to change the Return-Path of the
48 [mail()](http://php.net/mail) function.
50 ```php
51 use Zend\Mail;
53 $mail = new Mail\Message();
54 $mail->setBody('This is the text of the email.');
55 $mail->setFrom('Freeaqingme@example.org', 'Dolf');
56 $mail->addTo('matthew@example.com', 'Matthew');
57 $mail->setSubject('TestSubject');
59 $transport = new Mail\Transport\Sendmail('-freturn_to_me@example.com');
60 $transport->send($mail);
61 ```
63 > ### Chose your transport wisely
65 > Although the sendmail transport is the transport that requires least
66 > configuration, it may not be suitable for your production environment. This is
67 > because emails sent using the sendmail transport will be more often delivered
68 > to SPAM-boxes. This can partly be remedied by using the
69 > [SMTP Transport](transport/intro.md#smtp-transport-usage) combined with an SMTP
70 > server that has an overall good reputation. Additionally, techniques such as
71 > SPF and DKIM may be employed to ensure even more email messages are delivered
72 > successfully.
74 > ### Warning: Sendmail Transport and Windows
76 > As the PHP manual states, the `mail()` function has different behaviour on
77 > Windows than it does on \*nix based systems. Using the sendmail transport on
78 > Windows will not work in combination with `addBcc()`.  The `mail()` function
79 > will send to the BCC recipient such that all the other recipients can see that
80 > address as the recipient!
82 > Therefore if you want to use BCC on a windows server, use the SMTP transport
83 > for sending!