-
Hello everyone, here is my problem:
I have a friend who has installed Cloudron on his server, and as I needed something to put my site I asked him if it does not bother him to put me an application (LAMP). He proposed me to create a mailbox with roundcube (caranouga@caradev.ml) except that the problem is that the mail function of cloudron does not work!:
function cloudronmail($to, $subject, $body, $headers) { $smtp = stream_socket_client('tcp://' . getenv('CLOUDRON_MAIL_SMTP_SERVER') . ':' . getenv('CLOUDRON_MAIL_SMTP_PORT'), $eno, $estr, 30); $B = 8192; $c = "\r\n"; $s = getenv('CLOUDRON_MAIL_FROM'); fwrite($smtp, 'helo ' . getenv('HOSTNAME') . $c); $junk = fgets($smtp, $B); // Envelope fwrite($smtp, 'mail from: ' . $s . $c); $junk = fgets($smtp, $B); fwrite($smtp, 'rcpt to: ' . $to . $c); $junk = fgets($smtp, $B); fwrite($smtp, 'data' . $c); $junk = fgets($smtp, $B); // Header fwrite($smtp, 'To: ' . $to . $c); if(strlen($subject)) fwrite($smtp, 'Subject: ' . $subject . $c); if(strlen($headers)) fwrite($smtp, $headers); // Must be \r\n (delimited) fwrite($smtp, $headers . $c); // Body if(strlen($body)) fwrite($smtp, $body . $c); fwrite($smtp, $c . '.' . $c); $junk = fgets($smtp, $B); // Close fwrite($smtp, 'quit' . $c); $junk = fgets($smtp, $B); fclose($smtp); }
Here is what I put:
<?php function cloudronmail($to, $subject, $body, $headers) { $smtp = stream_socket_client('tcp://' . getenv('CLOUDRON_MAIL_SMTP_SERVER') . ':' . getenv('CLOUDRON_MAIL_SMTP_PORT'), $eno, $estr, 30); $B = 8192; $c = "\r\n"; $s = getenv('CLOUDRON_MAIL_FROM'); fwrite($smtp, 'helo ' . getenv('HOSTNAME') . $c); $junk = fgets($smtp, $B); // Envelope fwrite($smtp, 'mail from: ' . $s . $c); $junk = fgets($smtp, $B); fwrite($smtp, 'rcpt to: ' . $to . $c); $junk = fgets($smtp, $B); fwrite($smtp, 'data' . $c); $junk = fgets($smtp, $B); // Header fwrite($smtp, 'To: ' . $to . $c); if(strlen($subject)) fwrite($smtp, 'Subject: ' . $subject . $c); if(strlen($headers)) fwrite($smtp, $headers); // Must be \r\n (delimited) fwrite($smtp, $headers . $c); // Body if(strlen($body)) fwrite($smtp, $body . $c); fwrite($smtp, $c . '.' . $c); $junk = fgets($smtp, $B); // Close fwrite($smtp, 'quit' . $c); $junk = fgets($smtp, $B); fclose($smtp); } $headerss = 'From: caranouga@caradev.ml' . "\r\n" . 'Reply-To: m*********t@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); cloudronmail("m*********t@gmail.com", "Test", "Test", $headerss); echo 'test'; echo ' '; echo getenv('CLOUDRON_MAIL_SMTP_SERVER'); echo ' '; echo getenv('CLOUDRON_MAIL_SMTP_PORT'); echo ' '; getenv('CLOUDRON_MAIL_SMTPS_PORT'); echo ' '; echo getenv('CLOUDRON_MAIL_SMTP_USERNAME'); echo ' '; echo getenv('CLOUDRON_MAIL_SMTP_PASSWORD'); echo ' '; echo getenv('CLOUDRON_MAIL_FROM'); echo ' '; echo getenv('CLOUDRON_MAIL_DOMAIN'); echo ' '; getenv('HOSTNAME');
and a screen of what it gives: I would like to know if it is a problem with the cloudron or if I did something wrong
Thanks in advance for your help,
Caranouga
PS: The url of the roundcube is mail.miningheberg.ml, here is a screen of my creditentials.txt file:
Do not edit this file. It will be overwritten on any update or app restart and is autogenerated. Sendmail Credentials ==================== PHP usage Value Hostname: getenv('CLOUDRON_MAIL_SMTP_SERVER') mail Port: getenv('CLOUDRON_MAIL_SMTP_PORT') 2525 TLS Port: getenv('CLOUDRON_MAIL_SMTPS_PORT') 2465 Username: getenv('CLOUDRON_MAIL_SMTP_USERNAME') caranouga@caradev.ml Password: getenv('CLOUDRON_MAIL_SMTP_PASSWORD') the_password Address: getenv('CLOUDRON_MAIL_FROM') caranouga@caradev.ml Domain: getenv('CLOUDRON_MAIL_DOMAIN') caradev.ml
I changed my roundcube password to match the password of the creditentials file, but it does not work.
PS2: I have a last question I look at you I find variables that are not defined: $eno, $estr, etc... Is this normal? -
@caranouga hi there. I am not quite sure what this has to do with roundcube as such. I assume in your case you have to create a mailbox via the Cloudron dashboard and then make sure that LAMP instance is configured to use that as the mail sending identity.
Further do you have any error message which allow to dig into this deeper?
-
@nebulon Hello, thank you for your answer.
I already changed the LAMP email, and there is indeed a caranouga@caradev.ml mailbox.
I think I have an idea:
I just went back to the creditentials.txt file, and I saw that there is a getenv('CLOUDRON_MAIL_DOMAIN') variable that gives caradev.ml, maybe the mail function is using this domain to send emails instead of using miningheberg.ml.
Thanks to you,
CaranougaPS: I don't have an administrator account so I can't see the lamp and cloudron settings, so I have to wait for my friend to show me.
-
-
@caranouga said in Lamp mail don't work:
PS2: I have a last question I look at you I find variables that are not defined: $eno, $estr, etc... Is this normal?
What is $eno and $estr ?
-
I was able to send mails with PHPMailer.
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; $sender = getenv('CLOUDRON_MAIL_FROM'); $senderName = 'LAMP Test Email'; $recipient = 'test@cloudron.io'; $usernameSmtp = getenv('CLOUDRON_MAIL_SMTP_USERNAME'); $passwordSmtp = getenv('CLOUDRON_MAIL_SMTP_PASSWORD'); $host = getenv('CLOUDRON_MAIL_SMTP_SERVER'); $port = (int) getenv('CLOUDRON_MAIL_SMTP_PORT'); $subject = 'Cloudron test (SMTP interface accessed using PHP)'; $bodyText = "Email Test\r\nThis email was sent through the Cloudron SMTP interface using the PHPMailer class."; $bodyHtml = '<h1>Email Test</h1>'; $mail = new PHPMailer(true); try { $mail->isSMTP(); $mail->setFrom($sender, $senderName); $mail->Username = $usernameSmtp; $mail->Password = $passwordSmtp; $mail->Host = $host; $mail->Port = $port; $mail->SMTPAuth = true; $mail->addAddress($recipient); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $bodyHtml; $mail->AltBody = $bodyText; $mail->Send(); echo "Email sent!" , PHP_EOL; } catch (phpmailerException $e) { echo "An error occurred. {$e->errorMessage()}", PHP_EOL; //Catch errors from PHPMailer. } catch (Exception $e) { echo "Email not sent. {$mail->ErrorInfo}", PHP_EOL; } ?>
(Adapted from https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-php.html )