1 (edited by nkts96 2016-08-22 01:41:29)

Topic: How to send smtp authentificated email via php mail()?

======== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.5-1
- Linux/BSD distribution name and version: Ubuntu 14.04
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): PGSQL
- Web server (Apache or Nginx): Apache
- Manage mail accounts with iRedAdmin-Pro? No
- Related log if you're reporting an issue:
====

Hello, Zhang!
My problem is that I cant send email via php with smtp auth.
I accept email, that was send with usual mail(to, subject, message), but its marked by gmail as probable spam.
Unlike the email from roundcube (postmaster account) (if misunderstood see attachments)
Adding php mail's option $from ofc does nothing.

Also i tryed such lib as phpmailer, but i dont sure about i did all right.
Here is test script from phpmailer's site:

<?php
    require 'class.phpmailer.php';

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     = "mail.mydomain.com"; // SMTP server
   
    $mail->From     = "postmaster@rmydomain.com";
    $mail->AddAddress("mymail@gmail.com");

    $mail->Subject  = "First PHPMailer Message";
    $mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
    $mail->WordWrap = 50;

    if(!$mail->Send()) {
          echo 'Message was not sent.';
          echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
?>

but it isnt work. (Should i use mail.mydomain.com as smtp host or localhost/127.0.0.1?)
Then i paste additional lines:

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     = "mail.mydomain.com"; // SMTP server

    $mail->Port = "25";
    $mail->SMTPAuth = true;
    $mail->Username = "postmaster@mydomain.com";
    $mail->Password = "postmaster's pass";

    $mail->From     = "postmaster@mydomain.com";
    $mail->AddAddress("mymail@gmail.com");

and again no result:/

Some additional info: its fresh reinstall, first ubuntu distr, then iredmail, and at last some apache configs for my site.
All works, iredadmin and roundcube is ok.

There are many doubts, for e.g. about ports, some configs, etc. But its rather difficult to try all variants, so i hope a lot, that you can help me with it.

Post's attachments

irm1.png
irm1.png 5.07 kb, 1 downloads since 2016-08-21 

You don't have the permssions to download the attachments of this post.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2 (edited by RikuS 2016-08-22 03:29:32)

Re: How to send smtp authentificated email via php mail()?

Privet smile If your Roundcube is working, then there's nothing wrong with your server. But your php file configs are wrong, some things are missing and port number is invalid.

Here you can find default ports, look for Quick MUA Settings:
http://www.iredmail.org/docs/index.html

You can try with these settings:

<?php
    require 'class.phpmailer.php';
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "your.emailserver.hostname";
    $mail->Port = "587";
    $mail->SMTPSecure = "tls";
    $mail->SMTPAuth = true;
    $mail->From = "sender@domain.com";
    $mail->Username = "sender@domain.com";
    $mail->Password = "sender@domain.com password";
    $mail->AddAddress("recipient@domain.com");
    $mail->Subject  = "First PHPMailer Message";
    $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
    $mail->WordWrap = 50;
    if(!$mail->Send()) {
          echo 'Message was not sent.';
          echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
?>

3

Re: How to send smtp authentificated email via php mail()?

Privet:)

RikuS wrote:

You can try with these settings:

Thanks a lot bro! There was some more issues with php(my fails), but now all works!
Later i found info about 587 port, but still dont even know about "$mail->SMTPSecure = "tls";".

So, thanks again!