折腾:
【未解决】阿里云ECS服务器CentOS中php用465端口发送邮件
期间,需要去搞清楚关于其中的PHPMailer的mail的参数:
SetFrom
AddReplyTo
AltBody
AddAddress
PHPMailer mail 参数
PHPMailer mail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <?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 = ' user@example.com '; / / 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(' 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; } |
“//显示的名字,可以随意定义
$toAddress =”951086941@qq.com“; //发送到的邮件地址
$mail->AddAddress(“$toAddress”, “Zjmainstay”);//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress(“收件人email”,”收件人姓名”)
//$mail->AddReplyTo(“”, “”);”
“在网上找到phpmailer的资源并把class.smtp.php和class.phpmailler.php类保存下来用于等下调用”
好像不需要其他php文件了。
“AddAddress–方法
7 出自:PHPMailer::AddAddress(),文件:class.phpmailer.php
8 说明:增加收件人。参数1为收件人邮箱,参数2为收件人称呼。例 AddAddress(“xiaoxiaoxiaoyu@xiaoxiaoyu.cn“,”xiaoxiaoyu”),但参数2可选,AddAddress(xiaoxiaoxiaoyu@xiaoxiaoyu.cn)也是可以的。
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的参数的含义