Topic: can't send mail through PHP PEAR Mail
==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 1.3.2 PGSQL version
- Deployed with iRedMail Easy or the downloadable installer? downloadable installer
- Linux/BSD distribution name and version: Ubuntu 20.04
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): PGSQL
- Web server (Apache or Nginx): Both (nginx forwarding to apache)
- Manage mail accounts with iRedAdmin-Pro? no
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====
I'm trying to send mail through PHP PEAR Mail.php using the smtp plugin, but it is failing for my iRedMail installation (not so for gmail smtp servers)..
here's the function i'm using :
require_once ('Mail.php');
function webmail_send_mail ($serverConfig, $from, $to, $subject, $body) {
$c = $serverConfig;
$connectString =
'{'.$c['IMAP']['domain'].':'.$c['IMAP']['port']
.($c['IMAP']['requiresSSL']?'/imap/ssl':'')
.($c['IMAP']['sslCertificateCheck']?'':'/novalidate-cert')
.'}INBOX.Sent';
$mbox = imap_open($connectString, $c['userID'], $c['userPassword']);
$params = array (
'host' => $c['SMTP']['domain'],
'port' => 25,//$c['SMTP']['port for TLS'],
'auth' => false,
//'auth' => true,
//'socket_options' => array('ssl' => array('verify_peer_name' => false, 'allow_self_signed' => true)),
'username' => $c['userID'],//array_key_exists('userID_smtp',$c) ? $c['userID_smtp'] : $c['userID'],
'password' => $c['userPassword']
);
// echo json_encode($params, JSON_PRETTY_PRINT);
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', $params);
$mail = $smtp->send ($to, $headers, $body);
if (PEAR::isError($mail)) {
echo $mail->getMessage();
} else {
echo 'SUCCESS';
}
}
here's the error message that i'm getting :
Failed to add recipient: rene.veerman.netherlands@gmail.com [SMTP: Invalid response code received from server (code: 554, response: 5.7.1 <localhost>: Helo command rejected: ACCESS DENIED. Your email was rejected because the sending mail server does not identify itself correctly (localhost))]"
however, i've set /etc/hosts and /etc/hostname to be something else than localhost, on both the sending machine and on the $params['host'] machine.
i've also tried using TLS to connect to the iRedMail installation :
$params = array (
'host' => $c['SMTP']['domain'],
'port' => $c['SMTP']['port for TLS'],
'auth' => true,
'socket_options' => array('ssl' => array('verify_peer_name' => false, 'allow_self_signed' => true)),
'username' => $c['userID'],//array_key_exists('userID_smtp',$c) ? $c['userID_smtp'] : $c['userID'],
'password' => $c['userPassword']
);
but this results in the following error message :
authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]
i've done extensive googling, but i can not find anyone who has solved this problem yet.
i'm hoping i can get some help here.
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.