本文适用于 windows用户,linux版本后续会补上
邮件发送链接去重置密码等操作很常见,之前我使用的phpmailer去送法邮件,phpmailer的特点很明显,简单、易操作,但是有一个值得注意的地方是phpmailer配置中使用的密码不是登录密码,而是 smtp 的独立密码,又称授权码, 下面问题来了,因为公司刚搭建的outlook邮箱不支持smtp授权码,听说原因是因为stmp授权码是要硬件支持,这就导致phpmailer不能使用,不得已只能使用php自带的mail函数去发送邮件,废话不多说了。
第一步:先去下载sendmail 地址:http://download.youkuaiyun.com/detail/qq_33237412/9775176
第二步:将sendmail.zip解压,我是解压到 C:\wamp 下
第三步:修改php.ini文件,将SMTP、sendmail_from、smtp_port 这三行注释掉,配置sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
具体修改如下:
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port =
; http://php.net/sendmail-from
;sendmail_from =
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
mail.add_x_header = On
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
; uncomment to enable logging
; uncomment to enable debugging
auth_password=登录密码
; following three lines. do not enable unless it is required.
pop3_username=
pop3_password=
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// 当发送 HTML 电子邮件时,请始终设置 content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// 更多报头
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>