thinkphp php 使用mail---sendmial函数去发送邮件

本文适用于 windows用户,linux版本后续会补上

邮件发送链接去重置密码等操作很常见,之前我使用的phpmailer去送法邮件,phpmailer的特点很明显,简单、易操作,但是有一个值得注意的地方是phpmailer配置中使用的密码不是登录密码,而是 smtp 的独立密码,又称授权码,   下面问题来了,因为公司刚搭建的outlook邮箱不支持smtp授权码,听说原因是因为stmp授权码是要硬件支持,这就导致phpmailer不能使用,不得已只能使用php自带的mail函数去发送邮件,废话不多说了。

第一步:先去下载sendmail 地址:http://download.csdn.net/detail/qq_33237412/9775176

第二步:将sendmail.zip解压,我是解压到 C:\wamp

第三步:修改php.ini文件,将SMTPsendmail_from、smtp_port 这三行注释掉,配置sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

具体修改如下:

            

[mail function]
; For Win32 only.
; http://php.net/smtp
; SMTP =
; http://php.net/smtp-port
; smtp_port =
; For Win32 only.
; http://php.net/sendmail-from
; sendmail_from =
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; 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 =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; 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


第四步:修改sendmail文件中的sendmail.ini文件

smtp_server=smtp.demo.com.cn
; smtp port (normally 25)
smtp_port=25   端口
; SMTPS (SSL) support
;   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
smtp_ssl=TLS 
; the default domain for this server will be read from the registry
; 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
;default_domain=mydomain.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=登录名
auth_password=登录密码
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines.  do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
force_sender= demo@demo.com.cn  这边是发件人的邮箱

下面就可以发送邮件了

<?php

$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);
?>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值