Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Installation/Configuration

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 14th October 2010, 11:08
DKLeader DKLeader is offline
Senior Member
 
Join Date: Sep 2010
Location: Ishoej, Denmark
Posts: 115
Thanks: 7
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
Sponsored Links
  #2  
Old 14th October 2010, 12:20
Nicram Nicram is offline
Member
 
Join Date: Mar 2010
Location: PL
Posts: 59
Thanks: 21
Thanked 9 Times in 7 Posts
Send a message via ICQ to Nicram Send a message via AIM to Nicram Send a message via Yahoo to Nicram Send a message via Skype™ to Nicram
Default

What shows Your log files?
Like /var/log/maillog or /var/logmessages ?
It should say what is wrong.
Reply With Quote
  #3  
Old 14th October 2010, 12:59
DKLeader DKLeader is offline
Senior Member
 
Join Date: Sep 2010
Location: Ishoej, Denmark
Posts: 115
Thanks: 7
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4  
Old 14th October 2010, 14:08
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,202
Thanks: 829
Thanked 5,420 Times in 4,262 Posts
Default

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?
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #5  
Old 14th October 2010, 14:56
itanium itanium is offline
Member
 
Join Date: Jul 2008
Location: france
Posts: 37
Thanks: 18
Thanked 3 Times in 3 Posts
Default

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 =
Reply With Quote
  #6  
Old 14th October 2010, 17:23
DKLeader DKLeader is offline
Senior Member
 
Join Date: Sep 2010
Location: Ishoej, Denmark
Posts: 115
Thanks: 7
Thanked 0 Times in 0 Posts
Default

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
__________________
VoiceMe
Communications


Hosted at :
SuperWeb.dk
a part of VoiceMe
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 17:26
Installing PEAR PHP - Are there any security issues installing Pear? mxc General 2 10th July 2009 06:22
suphp pear php cat Installation/Configuration 0 3rd February 2009 19:17
PHP Open_basedir and PEAR DaddyFix Installation/Configuration 3 26th October 2006 08:11
Downgrade php5 to php4.4.2 llizards Installation/Configuration 4 13th March 2006 23:58


All times are GMT +2. The time now is 06:23.


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