HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   ISPConfig3 - Sending emails using PHP and Pear (http://www.howtoforge.com/forums/showthread.php?t=49429)

DKLeader 14th October 2010 11:08

ISPConfig3 - Sending emails using PHP and Pear
 
First : Not sure if this goes in this part of the forum - sorry if it is misplaced.

On my multiserver setup (Debian) I am trying to get emails sent from PHP on the sites. Since all normal mail sending from PHP does not work on a multiserver system I decided to try using Pear.

My PHP file looks like this :
Code:

<?php
  require_once "Mail.php";
  require_once 'Mail/mime.php';


  // Get user information entered on form.
  $Kontakt_FuldtNavn = $_REQUEST['Kontakt_FuldtNavn'] ;
  $baadnavn = $_REQUEST['baadnavn'] ;
  $foraar = $_REQUEST['foraar'] ;
  $efteraar = $_REQUEST['efteraar'] ;
  $starthavn = $_REQUEST['starthavn'] ;
  $tidligere = $_REQUEST['tidligere'] ;
  $senestaar = $_REQUEST['senestaar'] ;
  $Adresse = $_REQUEST['Adresse'] ;
  $postnr = $_REQUEST['postnr'] ;
  $by = $_REQUEST['by'] ;
  $email = $_REQUEST['email'] ;
  $dsklub = $_REQUEST['dsklub'] ;
  $baadtype = $_REQUEST['baadtype'] ;
  $skrogfarve = $_REQUEST['skrogfarve'] ;
  $sejlnr = $_REQUEST['sejlnr'] ;
  $lystal = $_REQUEST['lystal'] ;
  $lgd = $_REQUEST['lgd'] ;
  $brd = $_REQUEST['brd'] ;
  $depl = $_REQUEST['depl'] ;

  // Some info on who is sending.
  $from = "24timer@24-timerssejlads.dk";
  $to = "24timer@24-timerssejlads.dk, $email";
  $subject = "24Timer - Tilmelding";
   
  // Some info on what smtp we are going to use.
  $host = "mail.24-timerssejlads.dk";
  $username = "some@thingi.know";
  $password = "somethingiknow";
  $crlf = "\n";
   
// Message start
$html = "<html>
<body>HTML TEST MESSAGE</body>
</html>";

$hdrs = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$mime = new Mail_Mime($crlf);
$mime->setHTMLBody($html);
print_r($html);

$body = $mime->get();
$headers = $mime->headers($hdrs);

$smtp =& Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);
   
  if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
  }
?>

I have changed the message part to above during testing. I have it running on http://24-timerssejlads.dk/sendtilmeld.php

First of it seems to work fine - execpt it doesn't send any emails.
Anuone got a solution or maybe another way to send emails from within PHP using SMTP on another server.

Nicram 14th October 2010 12:20

What shows Your log files?
Like /var/log/maillog or /var/logmessages ?
It should say what is wrong.

DKLeader 14th October 2010 12:59

Forgot something in my first part :

Did check mail.err - no errors since I fixed my problems with mysql.

Also forgot to mention that the emails are received but they are empty.

//DKLeader

till 14th October 2010 14:08

Normal sending of mails works fine on multiserver systems. So if it does not work on yours, then there must be a misconfiguration of the email system and this should be fixed instaed of switching to pear.

So which exact errors do you get in the mail.log when you use the php mail() function?

itanium 14th October 2010 14:56

Do you have a email server on the web server like postfix or sendmail?

In the multiserver setup, i cannot find any install of a sendmail or postfix for webserver.

You can also check the php.ini for sendmail_path = sendmail -t -i =

DKLeader 14th October 2010 17:23

Ok, did some changes after reading the replies.
First of postfix was also running on my web server (192.168.1.90 - web.superweb.dk) - must have been from when I ran all as single server trying out ISPConfig3.

The PHP I have used for testing now looks like this :
Code:

<?php
$reciever = "24timer@24-timerssejlads.dk";
$subject = "Et emnefelt";

$massage = "<h1 style='background-color: #006699'>
            This is a test mail
          </h1>";

$header  = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$header .= "from:24timer@24-timerssejlads.dk";

mail($reciever, $subject, $message, $header);
?>

In the log there was some errors regarding connection to the mysql.
Changed all mysql-*.cf files to have the same user and pasword as the mail server (192.168.1.60 - mail.superweb.dk)
Also changed the host in same files to 192.168.1.60

My main.cf looks like this (after my changes) :
Code:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = /usr/share/doc/postfix

# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = mail.superweb.dk
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.superweb.dk
relayhost =
mynetwork = mail.superweb.dk
# mynetworks = 127.0.0.0/8 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
html_directory = /usr/share/doc/postfix/html
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /var/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
smtpd_sasl_auth_enable = yes
virtual_gid_maps = static:5000
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf, reject_unauth_destination
smtpd_tls_security_level = may
transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf
relay_domains = mysql:/etc/postfix/mysql-virtual_relaydomains.cf
relay_recipient_maps = mysql:/etc/postfix/mysql-virtual_relayrecipientmaps.cf
virtual_create_maildirsize = yes
virtual_maildir_extended = yes
virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = "The user you are trying to reach is over quota."
virtual_overquota_bounce = yes
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_dom$
smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf
smtpd_client_restrictions = check_client_access mysql:/etc/postfix/mysql-virtual_client.cf
maildrop_destination_concurrency_limit = 1
maildrop_destination_recipient_limit = 1
virtual_transport = maildrop
header_checks = regexp:/etc/postfix/header_checks
mime_header_checks = regexp:/etc/postfix/mime_header_checks
nested_header_checks = regexp:/etc/postfix/nested_header_checks
body_checks = regexp:/etc/postfix/body_checks
content_filter = amavis:[192.168.1.60]:10024
receive_override_options = no_address_mappings

And from the mail.log :
Code:

Oct 14 17:01:28 SuperWebServer10 postfix/master[6261]: daemon started -- version 2.5.5, configuration /etc/postfix
Oct 14 17:01:41 SuperWebServer10 postfix/pickup[6262]: 50C5D3EC13E: uid=33 from=<www-data>
Oct 14 17:01:41 SuperWebServer10 postfix/cleanup[6271]: 50C5D3EC13E: message-id=<20101014150141.50C5D3EC13E@mail.superweb.dk>
Oct 14 17:01:41 SuperWebServer10 postfix/qmgr[6263]: 50C5D3EC13E: from=<www-data@SuperWebServer10.superweb.dk>, size=378, nrcpt=1 (queue active)
Oct 14 17:01:41 SuperWebServer10 postfix/smtp[6274]: connect to 192.168.1.60[192.168.1.60]:10024: Connection refused
Oct 14 17:01:41 SuperWebServer10 postfix/smtp[6274]: 50C5D3EC13E: to=<24timer@24-timerssejlads.dk>, relay=none, delay=0.07, delays=0.06/0.01/0/0, dsn=4.4.1, status=deferred (connect to 192.168.1.60[192.168.1.60]:10024: Connection refused)
Oct 14 17:02:10 SuperWebServer10 postfix/pickup[6262]: 0732F3EC13F: uid=33 from=<www-data>
Oct 14 17:02:10 SuperWebServer10 postfix/cleanup[6271]: 0732F3EC13F: message-id=<20101014150210.0732F3EC13F@mail.superweb.dk>
Oct 14 17:02:10 SuperWebServer10 postfix/qmgr[6263]: 0732F3EC13F: from=<www-data@SuperWebServer10.superweb.dk>, size=378, nrcpt=1 (queue active)
Oct 14 17:02:10 SuperWebServer10 postfix/smtp[6274]: connect to 192.168.1.60[192.168.1.60]:10024: Connection refused
Oct 14 17:02:10 SuperWebServer10 postfix/smtp[6274]: 0732F3EC13F: to=<24timer@24-timerssejlads.dk>, relay=none, delay=0.06, delays=0.06/0/0/0, dsn=4.4.1, status=deferred (connect to 192.168.1.60[192.168.1.60]:10024: Connection refused)

change IP in
Code:

content_filter = amavis:[192.168.1.60]:10024
to 127.0.0.1 in the main.cf

And mail.log :
Code:

Oct 14 17:11:08 SuperWebServer10 postfix/pickup[6501]: 441983EC140: uid=33 from=<www-data>
Oct 14 17:11:08 SuperWebServer10 postfix/cleanup[6520]: 441983EC140: message-id=<20101014151108.441983EC140@mail.superweb.dk>
Oct 14 17:11:08 SuperWebServer10 postfix/qmgr[6502]: 441983EC140: from=<www-data@SuperWebServer10.superweb.dk>, size=378, nrcpt=1 (queue active)
Oct 14 17:11:08 SuperWebServer10 postfix/smtp[6504]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
Oct 14 17:11:08 SuperWebServer10 postfix/smtp[6504]: 441983EC140: to=<24timer@24-timerssejlads.dk>, relay=none, delay=0.06, delays=0.06/0/0/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)

//DKLeader

DKLeader 14th October 2010 17:37

Extra to my port :

Just found out that amavis wasn't running.

mail.log after amavis start and restart of postfix :

Code:

Oct 14 17:25:26 SuperWebServer10 postfix/pickup[6821]: B27333EC141: uid=33 from=<www-data>
Oct 14 17:25:26 SuperWebServer10 postfix/cleanup[6830]: B27333EC141: message-id=<20101014152526.B27333EC141@mail.superweb.dk>
Oct 14 17:25:26 SuperWebServer10 postfix/qmgr[6822]: B27333EC141: from=<www-data@SuperWebServer10.superweb.dk>, size=378, nrcpt=1 (queue active)
Oct 14 17:25:26 SuperWebServer10 amavis[6698]: (06698-01) (!)connect_to_sql: unable to connect to DSN 'DBI:mysql:database=dbispconfig;host=127.0.0.1;port=3306': Can't connect to MySQL server on '127.0.0.1' (111)
Oct 14 17:25:26 SuperWebServer10 amavis[6698]: (06698-01) (!!)TROUBLE in process_request: connect_to_sql: unable to connect to any dataset at (eval 86) line 241, <GEN28> line 3.
Oct 14 17:25:26 SuperWebServer10 amavis[6698]: (06698-01) (!)Requesting process rundown after fatal error
Oct 14 17:25:26 SuperWebServer10 postfix/smtp[6833]: B27333EC141: to=<24timer@24-timerssejlads.dk>, relay=127.0.0.1[127.0.0.1]:10024, delay=0.14, delays=0.08/0.01/0.01/0.04, dsn=4.3.2, status=deferred (host 127.0.0.1[127.0.0.1] said: 421 4.3.2 Service shutting down, closing channel (in reply to RCPT TO command))
Oct 14 17:25:48 SuperWebServer10 postfix/pickup[6821]: 792DD3EC142: uid=33 from=<www-data>
Oct 14 17:25:48 SuperWebServer10 postfix/cleanup[6830]: 792DD3EC142: message-id=<20101014152548.792DD3EC142@mail.superweb.dk>
Oct 14 17:25:48 SuperWebServer10 postfix/qmgr[6822]: 792DD3EC142: from=<www-data@SuperWebServer10.superweb.dk>, size=378, nrcpt=1 (queue active)
Oct 14 17:25:48 SuperWebServer10 amavis[6699]: (06699-01) (!)connect_to_sql: unable to connect to DSN 'DBI:mysql:database=dbispconfig;host=127.0.0.1;port=3306': Can't connect to MySQL server on '127.0.0.1' (111)
Oct 14 17:25:48 SuperWebServer10 amavis[6699]: (06699-01) (!!)TROUBLE in process_request: connect_to_sql: unable to connect to any dataset at (eval 86) line 241, <GEN28> line 3.
Oct 14 17:25:48 SuperWebServer10 amavis[6699]: (06699-01) (!)Requesting process rundown after fatal error
Oct 14 17:25:48 SuperWebServer10 postfix/smtp[6833]: 792DD3EC142: to=<24timer@24-timerssejlads.dk>, relay=127.0.0.1[127.0.0.1]:10024, delay=0.07, delays=0.03/0/0.01/0.03, dsn=4.3.2, status=deferred (host 127.0.0.1[127.0.0.1] said: 421 4.3.2 Service shutting down, closing channel (in reply to RCPT TO command))


falko 15th October 2010 16:13

What's the output of
Code:

netstat -tap
?

DKLeader 15th October 2010 19:36

From both web and mail server :

Code:

web:~# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address          Foreign Address        State      PID/Program name
tcp        0      0 localhost:10024        *:*                    LISTEN      7162/amavisd (maste
tcp        0      0 localhost:10025        *:*                    LISTEN      8383/master
tcp        0      0 web.superweb.dk:mysql  *:*                    LISTEN      11268/mysqld
tcp        0      0 *:submission            *:*                    LISTEN      8383/master
tcp        0      0 *:sunrpc                *:*                    LISTEN      1763/portmap
tcp        0      0 *:ftp                  *:*                    LISTEN      11087/pure-ftpd (SE
tcp        0      0 web.superweb.dk:domain  *:*                    LISTEN      30034/mydns
tcp        0      0 localhost:domain        *:*                    LISTEN      30034/mydns
tcp        0      0 *:smtp                  *:*                    LISTEN      8383/master
tcp        0      0 *:27                    *:*                    LISTEN      14672/sshd
tcp        0      0 *:57182                *:*                    LISTEN      1774/rpc.statd
tcp        0    152 web.superweb.dk:27      148.122.180.7:56569    ESTABLISHED 29560/0
tcp        0      0 web.superweb.dk:mysql  db2.superweb.dk:44699  TIME_WAIT  -
tcp        0      0 web.superweb.dk:33478  192.168.1.40:mysql      TIME_WAIT  -
tcp        0      0 web.superweb.dk:49745  192.168.1.60:mysql      TIME_WAIT  -
tcp        0      0 web.superweb.dk:34342  192.168.1.40:mysql      ESTABLISHED 23984/php-cgi
tcp        0      0 web.superweb.dk:mysql  db1.superweb.dk:47513  TIME_WAIT  -
tcp6      0      0 [::]:www                [::]:*                  LISTEN      6656/apache2
tcp6      0      0 [::]:tproxy            [::]:*                  LISTEN      6656/apache2
tcp6      0      0 [::]:ftp                [::]:*                  LISTEN      11087/pure-ftpd (SE
tcp6      0      0 localhost:domain        [::]:*                  LISTEN      30034/mydns
tcp6      0      0 [::]:https              [::]:*                  LISTEN      6656/apache2
tcp6      0      0 [::]:27                [::]:*                  LISTEN      14672/sshd
tcp6      0      0 web.superweb.dk:www    b3091085.crawl.ya:35293 TIME_WAIT  -
tcp6      0      0 web.superweb.dk:www    b3091085.crawl.ya:35354 TIME_WAIT  -

Code:

mail:~# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address          Foreign Address        State      PID/Program name
tcp        0      0 *:51584                *:*                    LISTEN      2195/rpc.statd
tcp        0      0 *:imaps                *:*                    LISTEN      3363/dovecot
tcp        0      0 *:pop3s                *:*                    LISTEN      3363/dovecot
tcp        0      0 :10024                  *:*                    LISTEN      2044/amavisd (ch16-
tcp        0      0 :10025                  *:*                    LISTEN      31909/master
tcp        0      0 *:mysql                *:*                    LISTEN      2632/mysqld
tcp        0      0 *:submission            *:*                    LISTEN      31909/master
tcp        0      0 *:pop3                  *:*                    LISTEN      3363/dovecot
tcp        0      0 *:imap2                *:*                    LISTEN      3363/dovecot
tcp        0      0 :spamd                  *:*                    LISTEN      2718/spamd.pid
tcp        0      0 *:sunrpc                *:*                    LISTEN      2184/portmap
tcp        0      0 *:ftp                  *:*                    LISTEN      3260/pure-ftpd (SER
tcp        0      0 *:24                    *:*                    LISTEN      2541/sshd
tcp        0      0 *:smtp                  *:*                    LISTEN      31909/master
tcp        0    248 mail.superweb.dk:24    148.122.180.7:56613    ESTABLISHED 28385/0
tcp        0      0 mail.superweb.dk:57673  web.superweb.dk:mysql  TIME_WAIT  -
tcp6      0      0 [::]:www                [::]:*                  LISTEN      3542/apache2
tcp6      0      0 [::]:ftp                [::]:*                  LISTEN      3260/pure-ftpd (SER
tcp6      0      0 localhost:ipp          [::]:*                  LISTEN      3158/cupsd
tcp6      0      0 [::]:24                [::]:*                  LISTEN      2541/sshd
tcp6      0      0 [::]:https              [::]:*                  LISTEN      3542/apache2
mail:~#


falko 16th October 2010 14:46

Quote:

Oct 14 17:25:26 SuperWebServer10 amavis[6698]: (06698-01) (!)connect_to_sql: unable to connect to DSN 'DBI:mysql:database=dbispconfig;host=127.0.0.1;por t=3306': Can't connect to MySQL server on '127.0.0.1' (111)
I think the problem is that MySQL isn't listening on 127.0.0.1.


All times are GMT +2. The time now is 01:43.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.