最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】PHPMailer的参数的含义

参数 crifan 1152浏览 0评论
折腾:
【未解决】阿里云ECS服务器CentOS中php用465端口发送邮件
期间,需要去搞清楚关于其中的PHPMailer的mail的参数:
SetFrom
AddReplyTo
AltBody
AddAddress
PHPMailer mail  参数
PHPMailer mail
phpmailer 参数使用说明 – 红尘书生 – 博客园
PHPMailer/PHPMailer: The classic email sending library for PHP
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = '
smtp1.example.com
;
smtp2.example.com
';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '
[email protected]
';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('
[email protected]
', 'Mailer');
    $mail->addAddress('
[email protected]
', 'Joe User');     // Add a recipient
    $mail->addAddress('
[email protected]
');               // Name is optional
    $mail->addReplyTo('
[email protected]
', 'Information');
    $mail->addCC('
[email protected]
');
    $mail->addBCC('
[email protected]
');

    //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;
}
Tutorial · PHPMailer/PHPMailer Wiki
如何在PHP中使用PHPMailer发送邮件 – Zjmainstay学习笔记 | 是非明于学习,境界升于内省
“//显示的名字,可以随意定义
$toAddress =”[email protected]“;                                                                      //发送到的邮件地址
$mail->AddAddress(“$toAddress”, “Zjmainstay”);//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress(“收件人email”,”收件人姓名”)
//$mail->AddReplyTo(“”, “”);”
phpmailer发送邮件 – CSDN博客
“在网上找到phpmailer的资源并把class.smtp.php和class.phpmailler.php类保存下来用于等下调用”
好像不需要其他php文件了。
phpmailer 参数使用说明 – 红尘书生 – 博客园
“AddAddress–方法
  7 出自:PHPMailer::AddAddress(),文件:class.phpmailer.php
  8 说明:增加收件人。参数1为收件人邮箱,参数2为收件人称呼。例 AddAddress(“[email protected]“,”xiaoxiaoyu”),但参数2可选,AddAddress([email protected])也是可以的。
  9 函数原型:public function AddAddress($address, $name = ”) {} 
49 AddReplyTo–方法
50 出自:PHPMailer:: AddReplyTo()
51 文件:class.phpmailer.php
52 说明:增加回复标签,如”Reply-to”
53 参数1地址,参数2名称
54 函数原型:public function AddReplyTo($address, $name = ”) {} ”
【总结】
基本上PHPMailer的参数的意思很清楚了:
  • SetFrom:from,发件人,名字可选
  • AddAddress:to,发送给谁,可以添加多个账号,名字可选
  • AddReplyTo:添加回复标签,比如“Reply-to”
    • 此处不太清楚,不过可以忽略
  • AltBody:当客户端不支持html时会显示此内容

转载请注明:在路上 » 【已解决】PHPMailer的参数的含义

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.209 seconds, using 22.16MB memory