1

I want to use the pear mail extension to send SMTP authenticated emails. There are a lot of examples in the web... this is my code:

<?php
require_once "Mail.php";

$body = "Testtext";
$subject = "SMTP Testmail";
$mail_to = "valid.adress@test.com";
$mail_from = "valid.sender.adress@othertest.com";

//SMTP Verbindungsdaten
$host = "valid.smtp.com";
$username = "invalidusername@othertest.com";
$password = "validpasswordforotheruser";

$smtp = Mail::factory('smtp',
 array (
 'host' => $host,
 //'auth' => true,
 'auth' => true,
 'username' => $username,
 'password' => $password
));

$headers = array (
 'From' => $mail_from,
 'To' => $mail_to,
 'Subject' => $subject
);
$mail = $smtp->send($mail_to, $headers, $body);

if (PEAR::isError($mail)) {
 echo "Error during sending E-Mail : ". $mail->getMessage();
}
?>

The script worked well so I wanted to test the error case of this sample and changed the smtp user to something invalid and it sill worked... I have got my mail.

How can this be?

Greetings

edit: I have done an other test now and changed the smtp server to be something invalid... documentation say that there must be an "PEAR_MAIL_SMTP_ERROR_CONNECT" error... I'm getting the following output: "fsockopen() [function.fsockopen]: unable to connect to xx.xx.xx.xxx:25 (Connection refused) in /usr/local/lib/php/Net/Socket.php on line 108"

"Catchable fatal error: Object of class PEAR_Error could not be converted to string in /usr/local/lib/php/Net/SMTP.php on line 222"

Where does this IP coming from when the smtp name is invalid??? Can it be the server is overrules by any config?

4

1 に答える 1

2

これは、SMTP サーバーがログイン データを検証しないことを意味します。認証をまったく必要としないか、SMPT-after-POP (ちなみにこれは恐ろしく時代遅れです) をサポートしている可能性があります。つまり、対応する POP3 サーバーで最近 IP が認証された場合、SMTP サーバーは認証を要求しません。

サーバーを、gmail SMTP など、常に認証を必要とする可能性のあるものに変更してみてください。

于 2012-06-18T09:45:41.630 に答える