2017-10-04 21 views
0

我需要测试一个用于发送邮件的php脚本。我复制从PHPMailer的不同行为php代码

Ç运行代码:\的Inetpub \ wwwroot的\ WWW \销售\ send_test_mail.php

C:\的Inetpub \ wwwroot的\ WWW \ prd_reques \ provaMail.php

这些代码是由一个IIS 8服务器与PHP 5.3.28执行。代码如下:

<?php 
//require './PHPMailerAutoload.php'; 
// start PHPMailerAutoload.php 
function PHPMailerAutoload($classname) 
{ 
    //Can't use __DIR__ as it's only in PHP 5.3+ 
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php'; 
    if (is_readable($filename)) { 
     require $filename; 
    } 
} 

spl_autoload_register('PHPMailerAutoload'); 
// end PHPMailerAutoload.php 

$mail = new PHPMailer(true); 

$mail->AddAddress("[email protected]"); 
$mail->MsgHTML("TEST old server"); 

try 
{ 
    $mail->Subject = "TEST INTERPLANET"; 
    $mail->SetFrom("[email protected]"); 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Host  = "mail.interplanet.it"; // sets the SMTP server 
    $mail->Port  = 25;     // set the SMTP port for the GMAIL server 
    $mail->Username = "username";    // SMTP account username 
    $mail->Password = "password";  // SMTP account password 
    $result = $mail->Send(); 
} 
catch (phpmailerException $e) 
{ 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} 
catch (Exception $e) 
{ 
    echo $e->getMessage(); //Boring error messages from anything else! 
} 
?> 

我想了解这种现象的原因......

更新1添加代码PHPMailerAutoload.php脚本

+1

当你运行代码时会发生什么?你期望什么?一个可能的问题可能是使用相对路径的'require'语句...... – user2393256

+0

您需要说出“不同的行为”是什么。 – Synchro

+0

_send_test_mail.php_脚本在尝试_Mail.php_ no时运行时发送邮件。 – salem

回答

0

我发现此代码在线:

<?php 

$from_name = "My name"; 
$mail_from = "[email protected]"; 
$mail_to= "[email protected]"; 


$mail_subject= "Test message"; 
$mail_body= "This is a test message for my application"; 

$mail_headers = "From: " . $from_name . " <" . $mail_from. ">\r\n"; 
$mail_headers .= "Reply-To: " . $mail_from. "\r\n"; 
$mail_headers .= "X-Mailer: PHP/" . phpversion(); 

if (mail($mail_from, $mail_subject, $mail_body, $mail_headers)) 
    echo "successfully sent message to" . $mail_to; 
else 
    echo "Error. Message not sent."; 
?> 

它似乎很好的工作!

相关问题