欢迎各位兄弟 发布技术文章
这里的技术是共享的
事实上取消用户名密码认证,就可以发送了
最重要的两步
1)$mail->isSMTP();
2)$mail->SMTPAutoTLS = false;
第二种方法更简单些,参数更少些
第一种方法
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
* The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
error_reporting(E_ALL);
ini_set("display_errors", "1"); // shows all errors
//
ini_set("display_start_errors", "1"); // shows all errors // "display_startup_errors"
ini_set("log_errors", "on");
ini_set("error_log", "php_errorccc.log");
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP(); // 这个必须有 需要有
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = '10.54.21.20';
$mail->server_caps = array('EHLO'=>'bbbb-admin.com');
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 25;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPAutoTLS = false; //它这个邮箱 不用认证,即不用用户名密码就可以发送,奇怪
$mail->SMTPSecure = 'NTLM';
$mail->AuthType = 'NTLM';
$mail->Realm = "aaaaa.com.cn";
$mail->Workstation = 'aaaaa.com.cn';
//Whether to use SMTP authentication
$mail->SMTPAuth = false;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Username = "bbbb\\bbbbb";
$mail->Password = "ccccc";
$mail->From = 'Pingzhong.Shi@bbbb-admin.com';
$mail->FromName = "Pingzhong.Shi@bbbb-admin.com";
//Set who the message is to be sent from
$mail->setFrom('Pingzhong.Shi@aaaaa-ict.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('Pingzhong.Shi@aaaaa-ict.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('Pingzhong.Shi@aaaaa-ict.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("AAAAAAAAAAAA");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
//Section 2: IMAP
//Uncomment these to save your message in the 'Sent Mail' folder.
#if (save_mail($mail)) {
# echo "Message saved!";
#}
}
第二种方法
<?php
//define("CR_AUTHENTICATE", false);
//include_once("setup.php");
//
//ini_set('display_errors', 1); # enable PHP error reporting
//error_reporting(E_ALL);
include("class/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 5;
$mail->IsSMTP();
//$mail->SMTPDebug = 1;
//$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
//$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = "starttls";
//$mail->SMTPSecure = "starttls";
$mail->SMTPAuth = false; //锟絆锟斤拷SMTP锟斤拷要锟斤拷C
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = '10.54.21.20';
$mail->Port = 25;
$mail->CharSet = "utf-8";
$mail->Username = "pingzhong.shi@bbbb-admin.com";
$mail->Password = "XXXXXXXXXXXX";
$mail->From = 'pingzhong.shi@bbbb-admin.com';
$mail->FromName = "pingzhong.shi@lbbbb-admin.com";
//$mail->SetFrom("pingzhong.shi@bbbb-admin.com", "pingzhong.shi@bbbb-admin.com");
$mail->Subject = "PHPMailer ";
$mail->Body = "ccccccccccc ";
$mail->IsHTML(true);
$mail->AddAddress('pingzhong.shi@bbbb-admin.com', "test");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}