本人使用wamp集成开发环境,Apache2.4.4, Mysql5.6.12 , php5.4.12.开始的时候使用mail()发送邮件,更改配置始终无法成功,了解到mail()函数使用需要sendmail程序。又下载了sendmail程序扩展包。按照网上的说法也改好了php.ini和sendmail.ini。使用foxmail 7.1创建了自己的qq邮箱账户,开启了POP3/SMTP服务,更改发件服务器为POP3,使用和收件服务器相同的身份验证,结果还是报错:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8。以下是使用mail()函数发送邮件的php代码:
[php] view plain copy
<span style="font-size:14px"><?php
$to = "757006080@qq.com"
$subject = "Test mail"
$message = "Hello! This is a simple email message."
$from = "757006080@qq.com"
$headers = "From: $from"
$send=mail($to,$subject,$message,$headers)
if($send)
echo "Mail Sent"
else
echo "Sorry,mail sent failed!"
?></span>
在CSDN论坛上发现phpmailer可以方便快捷的发送邮件,以下写出详细使用教程:
1.需要下载PHPMailer文件包,(点击打开链接)
2.确认你的服务器已经系统支持socket,通过phpinfo()查看是否支持socket;
3.把文件解压到你的WEB服务器目录下,就可以使用PHPMailer发送邮件了。
以下为前台表单php代码:
[php] view plain copy
<span style="font-size:14px"><html>
<body>
<h3>phpmailer Unit Test</h3>
请你输入<font color="#FF6666">收信</font>的邮箱地址:
<form name="phpmailer" action="testemail.php" method="post">
<input type="hidden" name="submitted" value="1"/>
邮箱地址: <input type="text" size="50" name="to" />
<br/>
<input type="submit" value="发送"/>
</form>
</body>
</html></span>
以下为后台程序:
[php] view plain copy
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/
header("content-type:text/htmlcharset=utf-8")
ini_set("magic_quotes_runtime",0)
require('class.phpmailer.php')
try {
$mail = new PHPMailer(true)//New instance, with exceptions enabled
//$body = file_get_contents('contents.html')
//$body = preg_replace('/\\\\/','', $body)//Strip backslashes
$to = $_POST['to']
$mail->CharSet="GB2312"//设置邮件字符编码否则邮件会乱码
$mail->Encoding="base64"
$mail->IsSMTP() // tell the class to use SMTP
$mail->SMTPAuth = true // enable SMTP authentication
$mail->Port = 25 // set the SMTP server port
$mail->Host = "smtp.qq.com"// SMTP server
$mail->Username = "757006080@qq.com"// SMTP server username
$mail->Password = "000000000000" // SMTP server password
//$mail->IsSendmail() // tell the class to use Sendmail
$mail->AddReplyTo("757006080@qq.com","han qing")
$mail->From = "757006080@qq.com"
$mail->FromName = "han qing"
//$to = "hanqing757@gmail.com"
$mail->AddAddress($to)
$mail->Subject =$mail->Subject = "=?utf-8?B?" . base64_encode("First PHPMailer Message") . "?="
$mail->Body = "<h1>phpmailer演示</h1>这是用PHPMAILER发的第一份邮件,从QQ邮箱发到Google邮箱."
$mail->AddAttachment("F:/myloe.jpg")
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"// optional, comment out and test
$mail->WordWrap = 80// set word wrap
//$mail->MsgHTML($body)
$mail->IsHTML(true)// send as HTML
$mail->Send()
echo 'Message has been sent.'
} catch (phpmailerException $e) {
echo $e->errorMessage()
}
?>
Thinkphp3.2 PHPMailer 发送邮件结合QQ企业邮箱发送邮件下载附件PHPMailer解压到ThinkPHP\Library\Vendor在Common文件夹新建function.php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* 邮件发送函数
*/
function sendMail($to, $title, $content) {
Vendor('PHPMailer.PHPMailerAutoload')
$mail = new PHPMailer()//实例化
$mail->IsSMTP()// 启用SMTP
$mail->Host=C('MAIL_HOST')//smtp服务器的名称(这里以QQ邮箱为例)
$mail->SMTPAuth = C('MAIL_SMTPAUTH')//启用smtp认证
$mail->Username = C('MAIL_USERNAME')//你的邮箱名
$mail->Password = C('MAIL_PASSWORD') //邮箱密码
$mail->From = C('MAIL_FROM')//发件人地址(也就是你的邮箱地址)
$mail->FromName = C('MAIL_FROMNAME')//发件人姓名
$mail->AddAddress($to,"尊敬的客户")
$mail->WordWrap = 50//设置每行字符长度
$mail->IsHTML(C('MAIL_ISHTML'))// 是否HTML格式邮件
$mail->CharSet=C('MAIL_CHARSET')//设置邮件编码
$mail->Subject =$title//邮件主题
$mail->Body = $content//邮件内容
$mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"//邮件正文不支持HTML的备用显示
return($mail->Send())
用FTP上传工具上传即可。这里以8UFTP软件为例:
1、下载安装FTP软件,输入服务器IP地址,FTP的用户名和密码进行连接。
2、连接FTP后,找到要上传的PHP项目文件,上传到服务器即可。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)