开发者

Mail function problem in PHP

开发者 https://www.devze.com 2022-12-10 11:50 出处:网络
I am having trouble sen开发者_Go百科ding emails with PHP. Can you see any problems in my code? php.ini mail settings:

I am having trouble sen开发者_Go百科ding emails with PHP. Can you see any problems in my code?

php.ini mail settings:

[mail function]
SMTP = mail.ntserv.co.in
smtp_port = 26

Code:

<?php
$to = "vijay@gmail.com";
$subject = "Test mail";
$message = "hi, How r u";
$from = "vijay@ntserv.co.in";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

Output:

Warning: mail() [function.mail]: SMTP server response: 551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail. in C:\xampp\htdocs\vijay\demo\msg.php on line 7 Mail Sent.


the mail function doesn't handle authentication, like you have to pass an username and password to actually be able to send an email. GMail require you to login to send email, default setting to avoid being an open relay server(and so being open to send spam).

If you really want to use gmail.com as server, you would have to use some PEAR or Zend Framework (or anything else) library that can authenticate agains the mail server before sending, see this link for couple of examples.

A better way to go would be to setup a local SMTP server on your server or to use your provider SMTP server.

0

精彩评论

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