开发者

php mail: check whether server needs authentication or not?

开发者 https://www.devze.com 2023-01-13 06:55 出处:网络
On some servers, the PHP mail() f开发者_JAVA百科unction requires SMTP authentication (i.e., we have to provide an email address and password). How do I determine through a PHP script if the server req

On some servers, the PHP mail() f开发者_JAVA百科unction requires SMTP authentication (i.e., we have to provide an email address and password). How do I determine through a PHP script if the server requires authentication or not?


The PHP mail() function only returns true or false, signifying whether the e-mail was successfully handed off to the mailer or not. It isn't possible to get any extra information, because PHP doesn't even handle the mailing. It hands it off to sendmail or whatever is configured in PHP.ini.

To determine the reason for failure, you must use another method. I'd like to second shamittomar's suggestion of Pear's Mail package. It is excellent.

If you use Mail::send() in Pear, it will either return true or a PEAR_Error() object which you can call the getCode() method on and figure out if you have an SMTP authentication error.

See this for more details: http://pear.php.net/manual/en/package.mail.mail.send.php


Why not just test it out by sending a mail using SMTP authentication? You can easily use one of the following libraries to do so:

  1. PHPMailer.
  2. Pear Mail Package.
0

精彩评论

暂无评论...
验证码 换一张
取 消