ZF_使用zend_Mail发送邮件

<?php require('Zend/Loader/Autoloader.php'); //Zend_Loader::registerAutoload(); Zend_Loader_Autoloader::getInstance()->registerNamespace('Zend_');//Zend框架的名字空间 Zend_Loader_Autoloader::getInstance()->registerNamespace('zlb_');//我自己的类的名字空间 Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true); set_time_limit(0); //Zend_Loader::loadClass('Zend_Mail'); //Zend_Loader::loadClass('Zend_Mail_Transport_Smtp'); $mailTest = new Zend_Mail('utf-8'); $smtpTest = new Zend_Mail_Transport_Smtp('smtp.126.com',array ('name'=>'smtp.126.com','username'=>'[email protected]','password'=>'******','auth'=>'login')); $mailTest->addTo('[email protected]','zhaolibin'); $mailTest->setFrom('[email protected]','LiYong'); $mailTest->setReturnPath('[email protected]'); $mailTest->setSubject('TEST_SUBJECT'); $mailTest->setBodyText('test'); $mailTest->send($smtpTest); ?> 其他参考代码

通过 SendMail发送邮件 require_once 'Zend/Mail.php'; $mail = new Zend_Mail(); $mail->setBodyText('This is the text of the mail.'); $mail->setFrom('[email protected]', 'Some Sender'); $mail->addTo('[email protected]', 'Some Recipient'); $mail->setSubject('TestSubject'); $mail->send(); 通过 SMTP 发送邮件 <?php require_once 'Zend/Mail/Transport/Smtp.php'; $tr = new Zend_Mail_Transport_Smtp('mail.example.com'); Zend_Mail::setDefaultTransport($tr); 通过一个SMTP连接发送多个邮件 <?php // Load classes require_once 'Zend/Mail.php'; // Create transport require_once 'Zend/Mail/Transport/Smtp.php'; $transport = new Zend_Mail_Transport_Smtp('localhost'); // Loop through messages for ($i = 0; $i > 5; $i++) { $mail = new Zend_Mail(); $mail->addTo('[email protected]', 'Test'); $mail->setFrom('[email protected]', 'Test'); $mail->setSubject('Demonstration - Sending Multiple Mails per SMTP Connection'); $mail->setBodyText('...Your message here...'); $mail->send($transport); } 发送HTML邮件 <?php require_once 'Zend/Mail.php'; $mail = new Zend_Mail(); $mail->setBodyText('My Nice Test Text'); $mail->setBodyHtml('My Nice <b>Test</b> Text'); $mail->setFrom('[email protected]', 'Some Sender'); $mail->addTo('[email protected]', 'Some Recipient'); $mail->setSubject('TestSubject'); $mail->send(); 带附件的邮件 require_once 'Zend/Mail.php'; $mail = new Zend_Mail(); $at = $mail->createAttachment($myImage); $at->type = 'image/gif'; $at->disposition = Zend_Mime::DISPOSITION_INLINE; $at->encoding = Zend_Mime::ENCODING_8BIT; $at->filename = 'test.gif'; $mail->send(); 在 Zend_Mail_Transport_Smtp 中使用身份验证 require_once 'Zend/Mail.php'; require_once 'Zend/Mail/Transport/Smtp.php'; $config = array('auth' => 'login', 'username' => 'myusername', 'password' => 'password'); $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config); $mail = new Zend_Mail(); $mail->setBodyText('This is the text of the mail.'); $mail->setFrom('[email protected]', 'Some Sender'); $mail->addTo('[email protected]', 'Some Recipient'); $mail->setSubject('TestSubject'); $mail->send($transport);

你可能感兴趣的:(ZF_使用zend_Mail发送邮件)