Zend_mail Mail Reprint Please specify the source, respect for the original: http://blog.csdn.net/a437629292/article/details/41700009, e-mail: 1. Direct mail server send:
Directly using the mail server to send, that is, the PHP program is located on the server is the mail server (that is, configured as an SMTP mail server), and sent to the other party must also be a mail server, such as QQ mailbox, 163 mailbox, etc., they are directly using the SMTP protocol
2. Delegate other mail servers to send:
The PHP program entrusts the other mail server to send the mail (must condition: The server can surf the Internet), for example: Send the message using the Zend_mail plugin provided by Zend.
Second, the SMTP form of mail sent:
First, the delegation of other mail server to send the message, there must be a series of parameter settings: For example: You have to register a mailbox on the mail server, so configure the mailbox login name and password is necessary, there is the subject, content, recipients and so on.
See the code in detail:
<?php require_once ' zend/mail.php '; require_once ' zend/mail/transport/smtp.php '; class SendMail { private static $_config =array( ' auth ' = ' login ', ' username ' = ' [email protected] ', ' password ' = ' xxxxx ' ); // definition SMTP validation parameters, set the correct mailbox and login password private static $_mail =null; private static $_transport =null; Public static function Send ($title, $body, $address) { Try { $transport = new zend_mail_transport_smtp (' smtp.163.com ',self::$_config); // the object of the case test certificate $mail = new zend_mail (' UTF-8 '); // instantiating a Send mail object $mail->setbodyhtml ($body); // send the subject of the message $mail->setfrom (' [email protected] ','); // define the mailboxes used for sending messages $mail->addto ("$address","); // define a receive mailbox for a message $mail->setsubject ($title); // Defining message Topics $mail->send ($transport); // perform a send operation return True; } Catch (Exception $e) { $e->gettrace (); return False; } } } |
The key part of the code has been annotated, so wordy, ask me questions directly.
Iii. Examples of Use
When a message is sent, instantiate the SendMail class and call the Send method of the class to pass in the corresponding parameter.
See the code in detail:
$title =" test "; $body =' This is a test of PHP Mail sent from Marktao ! Please confirm </a> ';$address = ' [email protected] '; $sendMail = newsendMail (); $sendMail->send ($title, $body, $address); |
Title is the subject of the message (title)
Body is the message content and supports HTML format.
Address to receive mail
Iv. Summary
Config in SendMail, in fact, such as this configuration parameters, it is best to configure to the configuration file, and then read, so the extensibility is more powerful.
Another way is through Phpmailer, this is not to use the Zend internal mail class, need to download some class package, and then introduced to use.
Zend_mail Mail Sending (SMTP mode)