ZENDFRAMEWORK2 Learning Notes Send email

Source: Internet
Author: User

There are 2 ways to send email in ZF2, one is to send email through the system's mail program, and the other is to send email via SMTP protocol using the remote SMTP server.

The related classes are:

Use Zend\mail\message;//email message class uses zend\mail\transport\sendmail;//send class using the System mail application zend\mail\transport\smtp;// Send class using the remote SMTP server through the SMTP protocol use zend\mail\transport\smtpoptions;//to set the parameter class for the SMTP class

Use is also relatively simple, the following mail.qq.com SMTP server For example, a small number of code to achieve the ability to send email:

Use Zend\mail\message;use zend\mail\transport\sendmail;use zend\mail\transport\smtp;use Zend\Mail\Transport\ Smtpoptions;class TestController extends Abstractactioncontroller {//Send mail via SMTP public function sendsmtpmailaction (        {$msg = new Message ();                $msg->setfrom ("[email protected]", "xxxxx")->setto ("[email protected]", "yyyyy")        ->setsubject ("email Title")->setbody (' This was an Email! '); $smtpOpt = new Smtpoptions (Array (' name ' = ' smtp.qq.com ', ' host ' = ' smtp.qq.com ',//QQ's free mailbox service                The ' Port ', ' connection_class ' = ' login ', ' connection_config ' = = Array (            ' username ' + ' xxxxx ',//QQ account, or the character mailbox name of the character mailbox name ' password ' = ' 1234567890 ',//Email login password        ),        ));        $trans = new Smtp ();        $trans->setoptions ($SMTPOPT);        $trans->send ($msg);  return new Jsonmodel ();  }//Send mail via system mail program public Function sendmailaction () {$msg = new message ();                $msg->setfrom ("[email protected]", "xxxxx")->setto ("[email protected]", "yyyyy")        ->setsubject ("email Title")->setbody (' This was an Email! ');        $trans = new Sendmail ();        $trans->send ($msg);    return new Jsonmodel (); }}






ZENDFRAMEWORK2 Learning Notes Send email

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.