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.

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.