用php发送邮件SMTP
2011-05-04 10:43
387 查看
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth=true;
$mail->SMTPDebug=1;
$mail->SMTPSecure="ssl";
$mail->FromName = "same";
$mail->Host = "smtp.googlemail.com"; // specify main and backup server
#$mail->Host = "smtp.qq.com";
$mail->Port=465;
#$mail->Port=587;
$mail->Username="same@gmail.com";//用户名
$mail->Password="123456";//密码
#$mail->Username="1043223224@qq.com";
#$mail->Password="c123";
$mail->AddAddress("432855322@qq.com");//收件人邮箱
#$mail->AddAddress("same@gmail.com"); // name is optional
$mail->SetFrom("same@gmail.com");//发件人邮箱
$mail->AddReplyTo("same@gmail.com");//发件人邮箱
#$mail->WordWrap = 50; // set word wrap
#$mail->AddAttachment("c://temp//js-bak.sql"); // add attachments
#$mail->AddAttachment("c:/temp/11-10-00.zip");
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
echo "<br>";
if(!$mail->send()){
echo '<font color="red">'.'Message was not sent.'.'</font>';
echo '<font color="red">'.'Mailer error:something is wrong!'.'</font>';
}else{
echo 'Message has been sent.';
}
/*
# MAIL command, to establish the return address, a.k.a. Return-Path, 5321.From, mfrom, or envelope sender. This is the address for bounce messages.
# RCPT command, to establish a recipient of this message. This command can be issued multiple times, one for each recipient. These addresses are also part of the envelope.
# DATA to send the message text. This is the content of the message, as opposed to its envelope. It consists of a message header and a message body separated by an empty line.
#DATA is actually a group of commands, and the server replies twice: once to the DATA command proper, to acknowledge that it is ready to receive the text,
#and the second time after the end-of-data sequence, to either accept or reject the entire messag
*/
?>
用php发送邮件,使用的是PHPMailer库,不过由于之前选择的库版本太低,发生很多错误。配来配去的,配置文件都是那几个选项。
最后选择PHPMailer_v5.1.zip。但是用mantisbt发送邮件,却老是发送成功后不能跳转。
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth=true;
$mail->SMTPDebug=1;
$mail->SMTPSecure="ssl";
$mail->FromName = "same";
$mail->Host = "smtp.googlemail.com"; // specify main and backup server
#$mail->Host = "smtp.qq.com";
$mail->Port=465;
#$mail->Port=587;
$mail->Username="same@gmail.com";//用户名
$mail->Password="123456";//密码
#$mail->Username="1043223224@qq.com";
#$mail->Password="c123";
$mail->AddAddress("432855322@qq.com");//收件人邮箱
#$mail->AddAddress("same@gmail.com"); // name is optional
$mail->SetFrom("same@gmail.com");//发件人邮箱
$mail->AddReplyTo("same@gmail.com");//发件人邮箱
#$mail->WordWrap = 50; // set word wrap
#$mail->AddAttachment("c://temp//js-bak.sql"); // add attachments
#$mail->AddAttachment("c:/temp/11-10-00.zip");
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
echo "<br>";
if(!$mail->send()){
echo '<font color="red">'.'Message was not sent.'.'</font>';
echo '<font color="red">'.'Mailer error:something is wrong!'.'</font>';
}else{
echo 'Message has been sent.';
}
/*
# MAIL command, to establish the return address, a.k.a. Return-Path, 5321.From, mfrom, or envelope sender. This is the address for bounce messages.
# RCPT command, to establish a recipient of this message. This command can be issued multiple times, one for each recipient. These addresses are also part of the envelope.
# DATA to send the message text. This is the content of the message, as opposed to its envelope. It consists of a message header and a message body separated by an empty line.
#DATA is actually a group of commands, and the server replies twice: once to the DATA command proper, to acknowledge that it is ready to receive the text,
#and the second time after the end-of-data sequence, to either accept or reject the entire messag
*/
?>
用php发送邮件,使用的是PHPMailer库,不过由于之前选择的库版本太低,发生很多错误。配来配去的,配置文件都是那几个选项。
最后选择PHPMailer_v5.1.zip。但是用mantisbt发送邮件,却老是发送成功后不能跳转。
相关文章推荐
- PHP Mailer邮件发送失败发送失败! Mailer Error: SMTP connect() failed.
- linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co
- php SMTP发送邮件
- 在php中使用SMTP通过密抄批量发送邮件续:修正
- php使用smtp发送支持附件的邮件示例
- PHP基于SMTP发送邮件的的简单例程
- [php] php curl smtp发送邮件
- PHPMailer发送邮件失败:SMTP connect failed
- linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co
- php邮件发送的两种方式 smtp
- PHP使用SMTP发送邮件
- PHP SMTP发送邮件
- 在php中使用SMTP通过密抄批量发送邮件
- php通过smtp发送邮件
- php使用pear_smtp发送邮件
- php发送smtp邮件
- 在PHP中使用Pear 的NetMail发送smtp邮件
- 资源马克-20161124- php smtp 带附件的邮件发送
- 使用PHP通过SMTP发送邮件新手指南zz
- php基于socket实现SMTP发送邮件的方法