localhost gives dovecot authenticator error using trying to auth smtp to external server

FirstMM

Member
Sep 21, 2008
5
0
51
Hi all,

I am not familiar with the cPanel set up so I am hoping someone can help me get this resolved.

I have a test PHP script which sends an email using Mail::factory and SMTP AUTH on port 465 to an external SMTP server.

If I "php mailertest.php" as root on the server then the email sends fine and there is (as expected) no hit on the mail log.

If, however, I try to run the same script via a webpage or as the cPanel user then I get the following in the maillog:

dovecot_login authenticator failed for <hostname> (localhost) <IP: port> 535 Incorrect authentication data (set_id=<emailaddress>)
SMTP connection from <hostname> (localhost) <IP: port> closed by QUIT


It appears that the server is attempting to use POP before SMTP on the localhost and thus failing to send.
The domain name has been removed from /etc/localdomains and added to /etc/remotedomains already and is correctly configured on the remote SMTP mail server.

Can someone please tell me what needs to be reconfigured?
Thanks!
 

FirstMM

Member
Sep 21, 2008
5
0
51
The code in your script is probably what's in need of some attention. This isn't a cPanel issue, it's an issue with your script.
Thanks for taking the time to reply Infopro :)

The code works fine when run as root from the server which is why I am confused!
Why would it run correctly as root (i.e. hit the remote server directly and correctly) and yet hit the local server POP before SMTP when run as the domain user if it is an error in the code?

In order to 100% guarantee that the code is not at fault (I took your suggestion seriously), I added it to another non cPanel server and it ran fine from there (not running as root but as a standard user).
 

FirstMM

Member
Sep 21, 2008
5
0
51
No way of knowing without seeing the script I don't think.
lol if it will make you happy the code comes from the following URL:
How to Send Email from a PHP Script Using SMTP Authentication (and SSL Encryption) - About Email, 2nd example.
Obviously I have already substituted the email addresses and SMTP server with real ones and not just pasted this into a shell window as is.

Shell output from cPanel server:
Code:
#runuser -l root -c 'php /home/testuser/mailer.php'
#[I]<p>Message successfully sent!</p>[/I]

runuser -l testuser -c 'php /home/testuser/mailer.php'
<p> authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]</p>
Shell output from non cPanel server:
Code:
#runuser -l root -c 'php /home/testuser/mailer.php'
#[I]<p>Message successfully sent!</p>[/I]

runuser -l testuser -c 'php /home/testuser/mailer.php'
<p>Message successfully sent!</p>

mailer.php
PHP:
<?php
 require_once "Mail.php";
 
 $from = "Sandra Sender <[email protected]>";
 $to = "Ramona Recipient <[email protected]>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 
 $host = "ssl://mail.example.com";
 $port = "465";
 $username = "smtp_username";
 $password = "smtp_password";
 
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 
 $mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>