uralmas / external-mailer
用于通过PHPMailer通过外部地址发送电子邮件的PHP邮件创建和传输类
0.2.0
2018-03-25 09:00 UTC
Requires
- php: >=5.5.0
- phpmailer/phpmailer: ^6.0
This package is not auto-updated.
Last update: 2024-09-24 04:21:50 UTC
README
以下情况下可能很有用
- 由于安全原因,在主机上禁用了通过标准功能发送电子邮件
- 需要发送邮件的网站感染了病毒,这些病毒负责发送垃圾邮件,并且主机已禁用发送邮件的功能
- 不同的网站有统一的邮件发送网关
安装与加载
PHPMailer可在Packagist上找到,并通过Composer安装ExternalMailer是推荐方式。只需将此行添加到您的composer.json文件中
"uralmas/external-mailer": "~0.2.0"
或者运行
composer require uralmas/external-mailer
使用
该库由两部分组成 - 客户端和服务器。客户端放置在需要发送邮件的网站上。服务器放置在作为发送网关的网站/IP上。
客户端
客户端构造器有两个参数
- 第一个是初始化服务器部分的脚本地址
- 第二个是客户端所在网站的路径地址,从该路径开始直到附加文件的地址(可选)即需要在addAttachment()函数中的文件路径中指定可从互联网访问的文件地址(如果指定了文件根地址,则可以省略)
不需要指定Debugoutput - 它将被替换为内部输出。要输出调试消息,请使用Client->getMessages()。
<?php require_once('./vendor/autoload.php'); try { //First argument - the address on which the script is located sending mail //Sencond - root of filepath $sender = new UralMas\ExternalMailer\Client('http://server.ru/', 'http://client.ru/'); $mail = $sender->createMailer(); //Server settings // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.mail.ru'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'user@mail.ru'; // SMTP username $mail->Password = 'password'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to /* Other parameters and functions to configuration instanse of PHPMailer */ //Send mails to Server part $send = $sender->send(); //Debug messages foreach ($sender->getMessages() as $message) { echo $message; } $result = $sender->getResult(); } catch (\Exception $e) { echo $e->getMessage(); }
服务器
<?php require_once('./vendor/autoload.php'); try { if (! isset($_POST['mailer'])) { throw new Exception('Not data are send'); } $mailerData = (string) $_POST['mailer']; $mailer = new \UralMas\ExternalMailer\Server($mailerData); echo $mailer->getResultSendMail(); } catch (Exception $e) { echo $e->getMessage(); }
许可证
本软件根据LGPL 2.1许可证分发。请阅读LICENSE以获取有关软件可用性和分发的信息。