rodrigoq / phpmailersendgrid
PHPMailer 扩展,用于通过 Sendgrid 发送电子邮件(或保存到文件)。
1.0.5
2022-02-26 15:01 UTC
Requires
- phpmailer/phpmailer: ^6.5
- sendgrid/sendgrid: ^7.10
This package is not auto-updated.
Last update: 2024-09-22 02:57:13 UTC
README
PHPMailer 扩展,用于通过 Sendgrid 发送电子邮件(或保存到文件)。
安装与加载
PHPMailerSendGrid 可在 Packagist 上找到(使用语义化版本控制),推荐通过 Composer 安装 PHPMailer。只需将以下行添加到您的 composer.json
文件中
"rodrigoq/phpmailersendgrid": "^1.0"
或者运行
composer require rodrigoq/phpmailersendgrid
依赖项
此项目依赖于
简单示例
<?php // Import PHPMailerSendGrid classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailerSendGrid; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader require '../vendor/autoload.php'; $mail = new PHPMailerSendGrid(true); // Passing `true` enables exceptions try { //SendGrid settings $mail->isSendGrid(); // Set mailer to use SendGrid // Set the SendGrid API Key, to do it securely check: // https://github.com/sendgrid/sendgrid-php/blob/master/README.md $mail->SendGridApiKey = ''; // SendGrid API Key. //Uncomment to save email to file // $mail->isFile(); // $mail->EmailFilePath = '/var/log/email/'; //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->Subject = 'Here is the subject'; $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; }
许可证
本软件按照 LGPL 3.0 许可证分发。请阅读 LICENSE 了解软件可用性和分发信息。