2017-10-04 51 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."; 
?> 

它似乎很好的工作!

相關問題