PHP code example of happy / send-email

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

    

happy / send-email example snippets




use happy\Email;

$smtper = new Email();

/**
 * setServer有五个参数
 * 第一个 $server 代理服务器的ip或者域名
 * 第二个 $username 认证账号
 * 第三个 $password 认证密码
 * 第四个 $port 代理服务器的端口,smtp默认25号端口
 * 第五个 $isSecurity 到服务器的连接是否为安全连接,默认false
 */
$smtper->setServer('smtp.qq.com', 'xxx', 'xxx');

/*setFrom参数为发件人地址*/
$smtper->setFrom('[email protected]');

/*setReceiver参数为收件人地址,多个收件人,调用多次*/
$smtper->setReceiver('[email protected]');

/*addAttachment参数为附件地址,没有附件可以不进行调用*/
$smtper->addAttachment("xxx.png"); 

/**setMail有两个参数
 * 第一个 $body 邮件主题
 * 第二个 $subject 邮件主体内容,可以是纯文本,也可是是HTML文本
 */
$smtper->setMail('xxx','xxx');

/*发送邮件*/
$smtper->send();