Board index   FAQ   Search  
Register  Login
Board index System Administration Server installation and configuration

sendmail and php configuration

Discuss server installationa nd configuration issues here

Moderators: macek, egami, gesf

sendmail and php configuration

Postby TrickyRic » Sat Apr 07, 2007 10:47 am

Having a little trouble with my server recently. I'm currently int he process of launching a second business venture and need to get my servers running properly. Until now my SMTP server, SendMail, has been configured only for web based contact forms and internal SMTP services. However my new membership system requires users to authenticate via E-Mail. In developing this system it has come to my attention that some POP services filter my generated E-Mails as spam, and in checking the headers of these E-Mails I wasn't entirely surprised.

I've spent all day reconfiguring both my PHP and SendMail services, rewriting scripts, and stressfully picking off the scab I once had.

Result? My headers are now mostly correct, yet my E-Mails appear to be blocked by all but a very poorly configured Hotmail account.

First off my PHP configuration now only sets the path variable, and doesn't use the -f parameter.

Code: Select all
/usr/sbin/sendmail -t -i


My SendMail configuration was built using the M4 macro, and my MC script contains the following.

Code: Select all
divert(-1)
divert(0)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`$Id: sendmail-procmail.mc,v 1.2 2004/12/07 01:59:31 g2boojum Exp $')dnl
OSTYPE(linux)dnl
DOMAIN(generic)dnl
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`local_lmtp',`/usr/sbin/mail.local')dnl
FEATURE(`local_procmail')dnl
FEATURE(access_db)dnl
FEATURE(relay_hosts_only)dnl
define(`SMART_HOST',`post.demon.co.uk')
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl


Finally, my PHP now contains this.

Code: Select all
    $mail_subject = 'Account activation for '.$url;

    $mail_header = 'From: QWeb <'.$qwebs_email.'>'."\n";
    $mail_header .= 'Reply-To: QWeb <'.$qwebs_email.'>'."\n";
    $mail_header .= 'Return-Path: '.$qwebs_email."\n";
    $mail_header .= "X-Mailer: PHP v".phpversion()."\n";
    $mail_header .= 'MIME-Version: 1.0'."\n";
    $mail_header .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
    $mail_header .= 'Content-Transfer-Encoding: 8bit'."\n";

    $mail_body .= '<p>Thank you for registering an account with '.$url.'.</p><p>To activate your new account simply click the following link.</p><p><a href="http://'.$url.'/accounts-'.$activation_code.'.php">http://'.$url.'/accounts-'.$activation_code.'.php</a></p>'."\n\n";

//    ini_set('sendmail_path','/usr/sbin/sendmail -t -i -f '.$qwebs_email);
    mail($email, $mail_subject, $mail_body, $mail_header);
//    ini_restore('sendmail_path');

    $page_content .= '      <p>Your account has been created and an activation E-Mail has been sent to the address specified.</p>'."\n";


Note the ini_set and ini_restore functions appear to have no effect, maybe thats a Windows function only? I've commented them out for now.

When I attempt to send out mail now, the server logs something like the following.

Code: Select all
Apr  7 17:53:33 athlon1200 sendmail[28050]: l37HrXGG028050: from=apache, size=638, class=0, nrcpts=1, msgid=<200704071753.l37HrXGG028050@athlon1200.home>, relay=apache@localhost
Apr  7 17:53:33 athlon1200 sm-mta[28051]: l37HrXQY028051: from=<apache@athlon1200.home>, size=811, class=0, nrcpts=1, msgid=<200704071753.l37HrXGG028050@athlon1200.home>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Apr  7 17:53:33 athlon1200 sendmail[28050]: l37HrXGG028050: to=support@***********.co.uk, ctladdr=apache (81/81), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30638, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (l37HrXQY028051 Message accepted for delivery)
Apr  7 17:53:34 athlon1200 sm-mta[28053]: l37HrXQY028051: to=<support@***********.co.uk>, ctladdr=<apache@athlon1200.home> (81/81), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=120811, relay=post.mail.demon.net. [194.217.242.92], dsn=2.0.0, stat=Sent (OK id=1HaFAK-0007jM-DJ)


However The only time I actually recieve a message is if I send to a badly configured Hotmail account that doesn't reject anything. At which point my headers look fine, though I'm not sure why the Return-Path header is being set to apache@athlon1200.home.

Code: Select all
MIME-Version: 1.0
Received: from anchor-post-32.mail.demon.net ([194.217.242.90]) by bay0-mc12-f9.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Sat, 7 Apr 2007 11:09:38 -0700
Received: from marygrant.demon.co.uk ([83.104.39.156] helo=athlon1200.home)by anchor-post-32.mail.demon.net with esmtp (Exim 4.42)id 1HaFM1-000GqL-92for learnvbforfree@hotmail.com; Sat, 07 Apr 2007 18:09:38 +0000
Received: from athlon1200.home (localhost [127.0.0.1])by athlon1200.home (8.13.7/8.13.7) with ESMTP id l37I5dgY028096for <**************@hotmail.com>; Sat, 7 Apr 2007 18:05:39 GMT
Received: (from apache@localhost)by athlon1200.home (8.13.7/8.13.7/Submit) id l37I5dxF028095;Sat, 7 Apr 2007 18:05:39 GMT
X-Message-Info: LsUYwwHHNt29fZVHgbiPWmjLsI8yv20EjjnNQaQEvEEL1OorGR1MbrNVWV/UERPJ
X-Mailer: PHP v5.1.6-pl6-gentoo
Return-Path: apache@athlon1200.home
X-OriginalArrivalTime: 07 Apr 2007 18:09:39.0244 (UTC) FILETIME=[E868EEC0:01C7793F]


Any idea what I'm missing?

Thanks.

EDIT:
If I explicitly declare an E-Mail address in php.ini the E-Mail appears to be accepted by most POP servers, however since this configuration is global the server will then force all outgoing E-Mails sent from hosted sites to be given incorrect from addresses. The ideal solution would be the PHP ini_set() function, but this appears to be ignored on my Gentoo GNU/Linux system running Apache 2 and PHP 5. Am I missing a configuration setting? Whats more, use of the -f parameter implants an authentication warning in the headers, which could be used by some POP servers for spam filtering.

Code: Select all
X-Authentication-Warning: athlon1200.home: apache set sender to support@*************.com using -f


Thanks.

EDIT:
I've now added apache to the /etc/mail/trusted-users file, and rebuilt my sendmail configuration as follows.

Code: Select all
divert(-1)
divert(0)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`$Id: sendmail-procmail.mc,v 1.2 2004/12/07 01:59:31 g2boojum Exp $')$
OSTYPE(linux)dnl
DOMAIN(generic)dnl
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`local_lmtp',`/usr/sbin/mail.local')dnl
FEATURE(local_procmail)dnl
FEATURE(use_ct_file)dnl
FEATURE(access_db)dnl
FEATURE(relay_hosts_only)dnl
define(`SMART_HOST',`post.demon.co.uk')dnl
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl


The X-Authentication-Warning header still appears though, even after restarting the SendMail daemon.

Any advice?

Thanks.

EDIT:
Finally got it sending (somewhat slowly - I guess because its relaying rather than sending direct) without the need for a statically defined sender address in php.ini, with the following PHP.

Code: Select all
    $mail_subject = 'Account activation for '.$url;

    $mail_header = 'From: QWeb <'.$qwebs_email.'>'."\n";
    $mail_header .= 'Reply-To: QWeb <'.$qwebs_email.'>'."\n";
    $mail_header .= 'Return-Path: QWeb <'.$qwebs_email.'>'."\n";
    $mail_header .= "X-Mailer: PHP v".phpversion()."\n";
    $mail_header .= 'MIME-Version: 1.0'."\n";
    $mail_header .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
    $mail_header .= 'Content-Transfer-Encoding: 8bit'."\n";

    $mail_body .= '<p>Thank you for registering an account with '.$url.'.</p><p>To activate your new account simply click the following link.</p><p><a href="http://'.$url.'/accounts-'.$activation_code.'.php">http://'.$url.'/accounts-'.$activation_code.'.php</a></p>'."\n\n";

    mail($email, $mail_subject, $mail_body, $mail_header, '-f '.$qwebs_email);


However I still havn't managed to remove the authentication warning Apache is adding to the headers.

Any advice?

Thanks.
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada

Return to Server installation and configuration

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron