2012-01-20 82 views
4
<?php 

    require_once '../plugin/swift/lib/swift_required.php'; 

    // Create the Transport 
    $transport = Swift_SmtpTransport::newInstance('pod51003.outlook.com',587,'tls') 
    ->setUsername('[email protected]') 
    ->setPassword('pw') 
    ; 

    // Create the Mailer using your created Transport 
    $mailer = Swift_Mailer::newInstance($transport); 

    // Create a message 
    $message = Swift_Message::newInstance('Wonderful Subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) 
    ->setBody('Here is the message itself') 
    ; 

    // Send the message 
    $result = $mailer->send($message); 

    printf("Sent %d messages\n", $result); 

?> 

發送郵件原來:錯誤501使用雨燕郵件

 
Fatal error: Uncaught exception 'Swift_TransportException' 
with message 'Expected response code 250 but got code "501", with message "501 5.5.4 Invalid domain name "' 
in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php:422 

Stack trace: 
#0 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(306): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('501 5.5.4 Inval...', Array) 
#1 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php(224): Swift_Transport_AbstractSmtpTransport->executeCommand('HELO [::1]??', Array, Array) 
#2 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(323): Swift_Transport_EsmtpTransport->executeCommand('HELO [::1]??', Array) 
#3 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php(272): Swift_Transport_AbstractSmtpTransport->_doHeloCommand() 
#4 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(124) in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 422 

其實我按照教程直線,因此是任何事情,我在我的代碼省略? SMTP服務器信息有效。

External SMTP setting:
Server name: pod51003.outlook.com - you can also see the note below on how to determine the server name
Port: 587
Encryption method: TLS

添加行之後:還有另外一個錯誤:

 
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\StreamBuffer.php on line 102 

Fatal error: Uncaught exception 'Swift_TransportException' 
with message 'Unable to connect with TLS encryption' 
in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php:283 

Stack trace: 
#0 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(124): Swift_Transport_EsmtpTransport->_doHeloCommand() 
#1 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() 
#2 C:\xampp\htdocs\fyp\mail\send.php(26): Swift_Mailer->send(Object(Swift_Message)) 
#3 {main} thrown in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php on line 283 

回答

10

在這裏嘗試加入這一行,如下所示:

// Create the Transport 
$transport = Swift_SmtpTransport::newInstance('pod51003.outlook.com',587,'tls') 
->setUsername('[email protected]') 
->setPassword('pw') 
; 

// ADD THIS LINE 
$transport->setLocalDomain('[127.0.0.1]'); 

// Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

我猜你的SMTP服務器不喜歡/瞭解IPv6,基於您收到HELO命令的響應。

+0

添加行後的另一個錯誤,請看看,謝謝很多 – user782104

+0

我追加打開ssl – user782104

+0

仍然有問題550 5.7.1客戶端沒有權限發送作爲此發件人 – user782104