0

I am having trouble sending 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 = "[email protected]";
$subject = "Test mail";
$message = "hi, How r u";
$from = "[email protected]";
$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.

3
  • a little more detail would be helpful - for instance, are you getting an error message, or just not receiving the email? Commented Nov 6, 2009 at 2:23
  • Um, it looks as though you are trying to send an email from your own script using gmail's servers. That's not possible, surely... Commented Nov 6, 2009 at 2:26
  • Mr, cori, now i edited the code. error: showing like this 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. Commented Nov 6, 2009 at 3:26

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.