将class.phpmailer.php html电子邮件转换为class.smtp.php

时间:2016-02-22 19:57:33

标签: php email phpmailer

我花了最近两天的时间使用带有phpmailer的内部交换服务器将Web表单发送到外部域。

不幸的是,现在,语法不同,我的旧代码不起作用。

是否有人使用smtp.php类发送HTML电子邮件?

旧代码,只能在内部发送:

require "phpmailer/class.phpmailer.php"; 

$mail = new PHPMailer();  
$mail->IsSMTP();              
$mail->SMTPAuth = false;  
$mail->SMTPDebug = 2;       
$mail->SMTPSecure = false;      
$mail->Host = "10.10.10.10";
$mail->Port = 25;  


$mail->From = "user@company.com";
$mail->FromName = "user";
$mail->SetFrom("user@company.com", "user);


$mail->Subject = $_POST['company'].": New MFD(s) (Time Sensitive)"; 

$mail->AddEmbeddedImage('trans2.png', 'logo', 'trans2.png ');

$mail->AddAttachment("docs/install.xlsx"); 
$mail->MsgHTML($message1.$message2.$message3);


$mail->AddAddress($_POST['emailid'], ""); 
$mail->AddCC("user@company.com");
$result = $mail->Send();    
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
unset($mail);

}

新代码,适用于发送到外部域的交换服务器:

require("smtp.php");
require("sasl.php");

$from="user@company.com"; $sender_line=__LINE__;
$to="person@company.com";  $recipient_line=__LINE__;

if(strlen($from)==0)
    die("Please set the messages sender address in line ".$sender_line." of the script ".basename(__FILE__)."\n");
if(strlen($to)==0)
    die("Please set the messages recipient address in line ".$recipient_line." of the script ".basename(__FILE__)."\n");

$smtp=new smtp_class;

$smtp->host_name="mailserver"; /
$smtp->host_port=587;  
$smtp->ssl=0;  

$smtp->start_tls=1; 
$smtp->localhost="localhost";  
$smtp->direct_delivery=0;   
$smtp->timeout=10;  
$smtp->data_timeout=0;
$smtp->debug=1;  
$smtp->html_debug=1; 
$smtp->pop3_auth_host=""; 
$smtp->user="user"; 
$smtp->realm="myrealm";   
$smtp->password="mywonderfulpassword";             
$smtp->workstation="workstationname";      
$smtp->authentication_mechanism="NTLM"; 

if($smtp->direct_delivery)
{
    if(!function_exists("GetMXRR"))
    {

        $_NAMESERVERS=array();
        include("getmxrr.php");
    }

    else
    {
        $_NAMESERVERS=array();
        if(count($_NAMESERVERS)==0)
            Unset($_NAMESERVERS);
        include("rrcompat.php");
        $smtp->getmxrr="_getmxrr";
    }

}

if($smtp->SendMessage(
    $from,
    array(
        $to
    ),
    array(
        "From: $from",
        "To: $to",
        "Subject: Testing Manuel Lemos' SMTP class",
        "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
    ),
    "Hello $to,\n\nIt is just to let you know that your SMTP class is working just fine.\n\nBye.\n"))
    echo "Message sent to $to OK.\n";
else
    echo "Could not send the message to $to.\nError: ".$smtp->error."\n";

如何发送HTML电子邮件和添加附件?

1 个答案:

答案 0 :(得分:0)

无视,我能够让phpmailer与我的交换服务器一起工作

$mail = new PHPMailer();  

// Set up SMTP  
$mail->IsSMTP();               
$mail->SMTPAuth = true;  
$mail->SMTPDebug = 0;       
$mail->SMTPSecure = 'tls';     
$mail->Host = "exchangeserver.com";
$mail->Port = 587;  



$mail->Username   = $_POST['emailusername'] ; 
$mail->Password   = $_POST['emailpassword'] ;