phpmailer-amp/phpmailer-amp

PHPMailer-AMP 是支持 AMP 内容的 PHPMailer 库

v1.1.0 2024-08-24 19:18 UTC

This package is not auto-updated.

Last update: 2024-09-21 19:42:29 UTC


README

特性

  • AMPBody 属性
  • isAMP() 函数
  • 构建函数 msgAMP()
  • 5 种新的消息类型 - amp, alt_amp, alt_amp_inline, alt_amp_attach 和 alt_amp_inline_attach (混合纯文本、html 和 amp 内容以及带附件的 html, amp)

许可证

此软件根据 LGPL 2.1 许可证分发,附带 GPL 合作承诺。请阅读 LICENSE 了解软件的可用性和分发信息。

安装与加载

PHPMailer 可在 Packagist 上找到(使用语义版本控制),并通过 Composer 安装是推荐的方式。只需将以下行添加到您的 composer.json 文件中

"phpmailer-amp/phpmailer-amp": "^1.1.0"

或者运行

composer require phpmailer-amp/phpmailer-amp
<?php
use PHPMailerAMP\PHPMailerAMP;

发送带有 AMP 内容的消息的示例

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailerAMP\PHPMailerAMP\PHPMailer;
use PHPMailerAMP\PHPMailerAMP\SMTP;
use PHPMailerAMP\PHPMailerAMP\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailerAMP(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'smtp.example.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'user@example.com';                     //SMTP username
    $mail->Password   = 'secret';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     //Add a recipient
    $mail->addAddress('ellen@example.com');               //Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->isAMP(true);                                   //Enable AMP content             
    $mail->Subject = 'Here is the subject';
    $mail->AmpBody = 'This is the AMP message body <style amp4email-boilerplate>body{visibility:hidden}</style>'
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

特性计划

  • 代码重构

从 PHPMailer v.6.9.1 分支而来