previousIntroduction (Previous) (Next) Mail::send()next

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

Mail::factory()

Mail::factory() – creates a mailer instance

Synopsis

require_once 'Mail.php';

object &factory ( string $backend , array $params = array() )

Description

Creates a instance of a backend-specific mailer class.

Parameter

  • string $backend - the name of the backend "mail" ,"smtp" , "sendmail"

  • array $params - a array of backend specific parameters.

    List of parameter for the backends

    • mail

      • If safe mode is disabled, $params will be passed as the fifth argument to the PHP mail() function. If $params is an array, its elements will be joined as a space-delimited string.

    • sendmail

      • $params["sendmail_path"] - The location of the sendmail program on the filesystem. Default is /usr/bin/sendmail .

      • $params["sendmail_args"] - Additional parameters to pass to the sendmail. Default is -i .

    • smtp

      • $params["host"] - The server to connect. Default is localhost .

      • $params["port"] - The port to connect. Default is 25 .

      • $params["auth"] - Whether or not to use SMTP authentication. Default is FALSE.

      • $params["username"] - The username to use for SMTP authentication.

      • $params["password"] - The password to use for SMTP authentication.

      • $params["localhost"] - The value to give when sending EHLO or HELO. Default is localhost

      • $params["timeout"] - The SMTP connection timeout. Default is NULL (no timeout).

      • $params["verp"] - Whether to use VERP or not. Default is FALSE.

      • $params["debug"] - Whether to enable SMTP debug mode or not. Default is FALSE.

        Mail internally uses Net_SMTP::setDebug .

      • $params["persist"] - Indicates whether or not the SMTP connection should persist over multiple calls to the send() method.

Return value

object - a specific Mail instance or a PEAR_Error object on failure.

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
NULL "Unable to find class for driver xxx " Mailer backend class was not found. Check the $backend parameter, if correct reinstall and/or update your Mail package.

Note

This function should be called statically.

previousIntroduction (Previous) (Next) Mail::send()next

Download Documentation Last updated: Sun, 18 Oct 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: Joe
There is hard-coded -f option in Mail_sendmail->send so it is impossible to set it using $params['sendmail_args']. It is hard-coded to -f$from.

In my case it caused 'X-Authentication-Warning' in mail headers.
Note by: shaun@shaunfreeman.co.uk
When sending mail via smtp be careful with the $params["auth"] option, the docs say it set it either to true or false, but in my case this didn't work and only when I set it to the actual authentication method of the server it worked. In my case I had to set it to:

$params["auth"] = "PLAIN";

This little problem had me going around in circles for 2 weeks!