谢谢各位,总算搞定了。原来安装了postfix后就不用phpmailer了。 直接用mail()函数就可以发送邮件了,超级简单。smtp的服务器 密码什么都不需要了。
<?php
$to ="[email protected]";
$subject="test";
$msg="smtp test";
$headers="From:[email protected]";if(mail("$to","$subject","$msg","$headers"))
echo"success";
else
echo"fail";
?>
<?php
$to ="[email protected]";
$subject="test";
$msg="smtp test";
$headers="From:[email protected]";if(mail("$to","$subject","$msg","$headers"))
echo"success";
else
echo"fail";
?>
要不然就会被认为是垃圾邮件,
严重的会被封IP,直接拒收~
require_once("./lib/class.phpmailer.php");
include("lib/class.smtp.php");
$mail=new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // SMTP authentication
$mail->Host = 'smtpcom.263xmail.com'; // SMTP server
$mail->From ='[email protected]';
$mail->FromName='Web';
$mail->Subject='My subject';
$mail->Body ='Hello World';
$mail->AddAddress('[email protected]','xx');$mail->Username = "[email protected]"; // SMTP 账户名
$mail->Password = "x"; // SMTP 账户密码
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
echo "Message sent!";
}
?>
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = file_get_contents('contents.html');
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$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.xxxx.com"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "xxxx"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("[email protected]","xxxx");
$mail->From = "[email protected]";
$mail->FromName = "DJB";
$to = "[email protected]";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$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();
}
?>
apt-get install sendmail