The SMTP protocol allow the PHP to send emails. It supports the encryption with the server, in the connection (STARTTLS), authentication. To create valid emails, use the mail class. Then use
echo $smtp->send ("sender@example.com",
"recipient@example.com",
$mail->getMail ());
If there is an error, an exception is raised
Use the local server and STARTTLS if the server support it. On port 25 by default.
$smtp = new Domframework\Smtp ();
$smtp->connect ();
$rc = $smtp->send ("sender@example.com", "recipient@example.com",
"From: Sender <sender@example.com>\r\n".
"To: Recipient <recipient@example.com>\r\n".
"Subject: Test\r\n".
"Message-ID: ".md5 (rand ().time ()). "\r\n".
"Date: ".date ("r")."\r\n".
"\r\n".
"Message\r\n");
$smtp->disconnect ();
The result of $smtp->send is the last valid message from the server.
Example : 250 2.0.0 Ok: queued as DF735C3BBA
Use the port 465 by default. The server must be defined as the certificate is
validated, or an exception will be raised.
$smtp = new Domframework\Smtp ();
$smtp->server = "smtp.example.com";
$smtp->ssl = true;
$smtp->connect ();
$rc = $smtp->send ("sender@example.com", "recipient@example.com",
"From: Sender <sender@example.com>\r\n".
"To: Recipient <recipient@example.com>\r\n".
"Subject: Test\r\n".
"Message-ID: ".md5 (rand ().time ()). "\r\n".
"Date: ".date ("r")."\r\n".
"\r\n".
"Message\r\n");
$smtp->reset ();
$smtp->disconnect ();
Use the port 465 by default. The server must be defined as the certificate is
validated, or an exception will be raised.
$smtp = new Domframework\Smtp ();
$smtp->server = "smtp.example.com";
$smtp->ssl = true;
$smtp->user = "user@domain.tld";
$smtp->password = "*********";
$smtp->connect ();
$rc = $smtp->send ("sender@example.com", "recipient@example.com",
"From: Sender <sender@example.com>\r\n".
"To: Recipient <recipient@example.com>\r\n".
"Subject: Test\r\n".
"Message-ID: ".md5 (rand ().time ()). "\r\n".
"Date: ".date ("r")."\r\n".
"\r\n".
"Message\r\n");
$smtp->reset ();
$smtp->disconnect ();
Namespace Domframework
/** Allow to send mails by smtp
/** The authentication methods in an array. Allowed : plain, login
/** Debug mode
/** The debug file used to store all the communication between the client and the server. The file contains the passwords if used !
/** The authentication password allow to send SMTP mails
/** The SMTP port to use (if false, use 25 if no SSL or 465 if SSL, if user defined, use the user value)
/** The SMTP server name or IP
/** The SMTPS support by tunnelling the session in SSL transport
/** Check the certification chain in SSL mode
/** Activate STARTTLS if needed. Allowed values : none, may, encrypt
/** Check the certificate in STARTTLS
/** The Timeout between the answer of the SMTP server. If the server don't answer in this time, an exception is raised
/** The authentication user allow to send SMTP mails
/** Connect to the SMTP server
/** Disconnect from the SMTP server
/** Reset the session to start a new mail in the same SMTP connection
/** Send the mail to the users@param string $from
The email address used for the from enveloppe@param string|array $to
the recipient of the email. Not displayed in the email content@param string $completeMail
The content of the email@return
string the message from the server (where is stored the message queue identifier