Hi Everyone,

When I feed details in Enquiry Form and click on submit then, my email is not going. It displays error message as "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in E:\HostingSpaces\flashprop\flash-properties.com\wwwroot\sell.php on line 39".

Kindly, help. Thanks in advance.

Dani AI

Generated

Short summary: the server is requiring authenticated SMTP, so the PHP mail() path will not work here. As pointed out you need an SMTP-capable library; after switching to PEAR Mail you hit an SMTP authentication failure (535), which means the SMTP server rejected the credentials or the connection parameters (host/port/SSL) are wrong — not a PHP mail() bug.

Checklist to find the real cause:

  • Verify the SMTP credentials by logging into webmail or configuring them into a mail client (Thunderbird/Outlook). If that login fails, the username/password are wrong or the account is locked.
  • Make sure you are supplying the SMTP host and port to PEAR Mail (and using the "smtp" driver). Many people forget the host/port keys, or use the wrong port (587 vs 465). If the server expects SSL on port 465 you may need to prefix the host with ssl:// or otherwise enable TLS.
  • Ensure the authenticated account is allowed to send from the From address you set. Some servers refuse if the From address does not match the SMTP account or an approved alias.
  • Turn on verbose SMTP debugging so you can see the SMTP conversation. PEAR/Net_SMTP and other libraries have debug flags; that output will show exactly why auth failed.
  • If you are using a public provider (Gmail, Office365, etc.) check their current SMTP rules: some require app passwords, OAuth2, or specific security settings.

If you want a quick, robust alternative, try PHPMailer (simpler TLS/SSL handling). Example:

require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'admin@example.com';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'tls'; // or 'ssl'
$mail->Port = 587; // or 465
$mail->setFrom('admin@example.com');
$mail->addAddress('recipient@example.com');
$mail->Subject = 'Test';
$mail->Body    = 'Test message';
$mail->send();

If problems persist, capture the debug output and contact the mail host with that log; they can tell you whether you're hitting a blocked port, bad auth method, or an account policy.

Recommended Answers

All 10 Replies

The mail function does not support authentication. You'd need to use a tool to do this. Choices can be for example: PHPMailer, SwiftMailer or PEAR::Mail.

I used PEAR::Mail for sending mail. Still it is displaying me error message as "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\PHP5\PEAR\Mail\mail.php on line 153". The code is mentioned below: -

<?php
    include('pear_mail/Mail/Mail.php');

    $mail = Mail::factory("mail");

    $headers = array("From"=>"me@example.com", "Subject"=>"Test Mail");
    $body = "This is a test!";
    $mail->send("best@friend.com", $headers, $body);
?> 

SMTP server response: 530 SMTP authentication is required

If this is all code, you did not send your authentication (usually email/password).

I used PEAR::Mail for sending mail. Still it is displaying me error message as "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\PHP5\PEAR\Mail\mail.php on line 153". The code is mentioned below: -

<?php
    include('pear_mail/Mail/Mail.php');

    $mail = Mail::factory("mail");

    $headers = array("From"=>"me@example.com", "Subject"=>"Test Mail");
    $body = "This is a test!";
    $mail->send("best@friend.com", $headers, $body);
?> 
<?php
include('pear_mail/Mail/Mail.php');

$params = array($params["auth"]=>"TRUE","username"=>"admin@mydomain.com","password"=>"xyz");
$mail = Mail::factory("mail",$params);

$headers = array("From"=>"admin@mydomain.com", "Subject"=>"Test Mail");
$body = "This is a test!";
$mail->send("sender@senderdomain.com", $headers, $body);

?>

I modified my code. I added authentication. I created email id for e.g. admin@mydomain.com and I set password for this email id as "xyz". Now, I try sending mail, still it shows same error message "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\PHP5\PEAR\Mail\mail.php on line 156".

Kindly, help me.

Try:

$params = array("auth" => true, "username" => "admin@mydomain.com", "password" => "xyz");
$mail = Mail::factory("smtp", $params);
<?php
include('pear_mail/Mail/Mail.php');

$params = array($params["auth"]=>"TRUE","username"=>"admin@mydomain.com","password"=>"xyz");
$mail = Mail::factory("mail",$params);

$headers = array("From"=>"admin@mydomain.com", "Subject"=>"Test Mail");
$body = "This is a test!";
$mail->send("sender@senderdomain.com", $headers, $body);

?>

I modified my code. I added authentication. I created email id for e.g. admin@mydomain.com and I set password for this email id as "xyz". Now, I try sending mail, still it shows same error message "Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\PHP5\PEAR\Mail\mail.php on line 156".

Kindly, help me.

You posted the exact same reply as before. Did you even try my suggestion?

I tried the above code. But, now its now displaying error message on browser. But, when I echo the result of function i.e. $result = $mail->send("sender@senderdomain.com", $headers, $body);
echo "Result:".$result;

Then, it returns error message as "Result: authentication failure [SMTP: Invalid response code received from server (code: 535, response: Authentication failed. Restarting authentication process.)] ".

Kindly help me out.

So the code is now correct, but your mail server is rejecting the authentication. I can't guess what setting that would be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.