您的位置:首页 > 编程语言 > PHP开发

用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发送邮件,却老是发送成功后不能跳转。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: