1 (edited by NotLarry 2018-08-23 15:28:21)

Topic: PHP Sendmail from a remote server

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 0.9.8 MYSQL edition.
- Linux/BSD distribution name and version: Ubuntu 16.04.5 LTS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx - Default with install i believe.
- Manage mail accounts with iRedAdmin-Pro? Not Pro.
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.


Hi Guys,

Relatively simple issue I hope. I have server1: mail.domain.com running my iRedMail server.
If I put the below php form in that webserver, it sends emails.

I have a webserver, server2. domain.com running apache2, php7.0.
If i put the below form on that webserver, it does not send mail.

I have had a look at configuring sendmail and the only thing people tell me to add is the email address we're sending from, which doesn't seem right.

My /etc/php/7.0/apache2/php.ini

; For Win32 only.
; http://php.net/smtp
;SMTP = mail.domain.com
; http://php.net/smtp-port
smtp_port = 587

; For Win32 only.
; http://php.net/sendmail-from
; sendmail_from = admin@domain.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i -f admin@domain.com

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

The PHP form code that I use is:

<?php
if(isset($_POST['submit'])){
    $to = "admin@domain.com"; // this is your Email address #This is the only thing I changed on the this template, to reflect my actual email address.
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

The contents of my /var/log/mail.log:

Aug 23 02:53:59 trc sendmail[12869]: alias database /etc/mail/aliases rebuilt by root
Aug 23 02:53:59 trc sendmail[12869]: /etc/mail/aliases: 12 aliases, longest 10 bytes, 134 bytes total
Aug 23 02:53:59 trc sm-mta[12950]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Aug 23 02:55:10 trc sm-mta[1349]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Aug 23 03:04:37 trc sm-mta[2381]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Aug 23 03:32:40 trc sendmail[4196]: w7N3WeDw004196: from=admin, size=103, class=0, nrcpts=0, msgid=<201808230332.w7N3WeDw004196@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 04:52:28 trc sendmail[8724]: alias database /etc/mail/aliases rebuilt by root
Aug 23 04:52:28 trc sendmail[8724]: /etc/mail/aliases: 12 aliases, longest 10 bytes, 134 bytes total
Aug 23 04:52:31 trc sm-mta[2381]: restarting /usr/sbin/sendmail-mta due to signal
Aug 23 04:52:31 trc sm-mta[8772]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Aug 23 04:57:20 trc sendmail[8993]: w7N4vKme008993: from=admin, size=165, class=0, nrcpts=0, msgid=<201808230457.w7N4vKme008993@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 04:57:20 trc sendmail[8995]: w7N4vKih008995: from=admin, size=178, class=0, nrcpts=0, msgid=<201808230457.w7N4vKih008995@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 05:08:36 trc sendmail[9817]: w7N58apW009817: from=admin, size=168, class=0, nrcpts=0, msgid=<201808230508.w7N58apW009817@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 05:08:36 trc sendmail[9819]: w7N58aGf009819: from=admin, size=181, class=0, nrcpts=0, msgid=<201808230508.w7N58aGf009819@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 05:08:43 trc sendmail[9821]: w7N58hPm009821: from=admin, size=175, class=0, nrcpts=0, msgid=<201808230508.w7N58hPm009821@trc.com.w.alikunlun.com>, relay=admin@localhost
Aug 23 05:08:43 trc sendmail[9823]: w7N58htA009823: from=admin, size=188, class=0, nrcpts=0, msgid=<201808230508.w7N58htA009823@trc.com.w.alikunlun.com>, relay=admin@localhost

----

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

2

Re: PHP Sendmail from a remote server

You need to send email with smtp authentication

- server address: the hostname of ip address of your iRedMail server
- port: 587
- secure connection: starttls (or TLS)
- smtp username: full email address of your mail user
- smtp password: password of your mail user

3

Re: PHP Sendmail from a remote server

ZhangHuangbin wrote:

You need to send email with smtp authentication

- server address: the hostname of ip address of your iRedMail server
- port: 587
- secure connection: starttls (or TLS)
- smtp username: full email address of your mail user
- smtp password: password of your mail user

Thank you for this information, but where to I put it?!

4

Re: PHP Sendmail from a remote server

NotLarry wrote:

where to I put it?!

Your PHP code.
Please do a quick google search to know how to send email with smtp authentication in php.