PHP code example of easyswoole / smtp

1. Go to this page and download the library: Download easyswoole/smtp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

easyswoole / smtp example snippets


$mail = new \EasySwoole\Smtp\Mailer(false);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setTimeout(5);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setMaxPackage(1024 * 1024 * 2);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setHost("smtp.qq.com");

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setPort(465);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setSsl(true);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setUsername("[email protected]");
$mail->setPassword("xxxxx");

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setFrom("[email protected]");

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->addAddress("[email protected]");

/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setReplyTo("[email protected]");

/** @var \EasySwoole\Smtp\Mailer $mail **/
$text = new \EasySwoole\Smtp\Request\Text();
$text->setSubject("Smtp Test Title");
$text->setBody("Smtp Test Body");

// 添加附件 可选
$text->addAttachment(__FILE__,'附件重命名');

// 发送
$mail->send($text);

/** @var \EasySwoole\Smtp\Mailer $mail **/
$text = new \EasySwoole\Smtp\Request\Html();
$text->setSubject("Smtp Test Title");
$text->setBody("<h1>Smtp Test Body<h1>");

// 添加附件 可选
$text->addAttachment(__FILE__,'附件重命名');

// 发送
$mail->send($text);

try {
    /** @var \EasySwoole\Smtp\Mailer $mail **/
    $mail->send($text);
}catch (\EasySwoole\Smtp\Exception\Exception $exception) {

}

/** @var \EasySwoole\Smtp\Mailer $mail **/
/** @var \EasySwoole\Smtp\Protocol\Response $response **/
$response = $mail->send($text);