PHP code example of xiaosongshu / mail

1. Go to this page and download the library: Download xiaosongshu/mail 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/ */

    

xiaosongshu / mail example snippets

 
/** 发件人 你的邮箱地址 */
$user = '[email protected]';
/** 发件人授权码 在邮箱的设置,账户,smtp里面  */
$password = 'xxxxxxxx';
/** 邮箱服务器地址 */
$url = 'smtp.qq.com:25';

try {
    /** 实例化客户端 */
    $client = new \Xiaosongshu\Mail\Client();
    /** 配置服务器地址 ,发件人信息 */
    $client->config($url, $user, $password);
    /** 发送邮件 语法:[收件人邮箱] ,邮件主题, 邮件正文,[附件]  */
    $res = $client->send( ['[email protected]'],'标题', '正文呢',[__DIR__.'/favicon.ico',__DIR__.'/favicon2.ico',]);
    print_r($res);
} catch (Exception $exception) {
    print_r("发送邮件失败");
    print_r($exception->getMessage());
}