17.2. Sending via SMTP
السابق | فصل 17. Zend_Mail | التالي

## 17.2. Sending via SMTP

To send mail via SMTP, `Zend_Mail_Transport_Smtp` needs to be created and registered with `Zend_Mail` before the `send()` method is called. For all remaining `Zend_Mail::send()` calls in the current script, the SMTP transport will then be used:

مثال 17.2. Sending E-Mail via SMTP

    <?php
    require_once 'Zend/Mail/Transport/Smtp.php';
    $tr = new Zend_Mail_Transport_Smtp('mail.example.com');
    Zend_Mail::setDefaultTransport($tr);
    ?>

The `setDefaultTransport()` method and the constructor of `Zend_Mail_Transport_Smtp` are not expensive. These two lines can be processed at script setup time (e.g., config.inc or similar) to configure the behaviour of the `Zend_Mail` class for the rest of the script. This keeps configuration information out of the application logic - whether mail is sent via SMTP or `mail()`, what mail server to use, etc.

السابق | أعلى | التالي
فصل 17. Zend_Mail | البداية | 17.3. Sending Multiple Mails per SMTP Connection