Understanding sendmail config
I am trying to get php to send mail via the "mail() command, on a Ubuntu linux box. The mail appears to be going and then getting dropped by send mail - and I am at a loss as to what to do about it.
The php mail() function returns true. The mail is not delivered. I have set up evolutoin to deliver vi SMTP on localhost, and sent an email to the same user - and it is delivered.
The /var/log/mail.log file contains the following entries.
Jul 9 15:15:34 anake postfix/pickup[1292]: 02879340040: uid=33 from=<www-data>
Jul 9 15:15:34 anake postfix/cleanup[2079]: 02879340040: message-id=<20110709141534.02879340040@anake>
Jul 9 15:15:34 anake postfix/qmgr[1293]: 02879340040: from=<www-data@anake.ianhobXXson.co.uk>, size=411, nrcpt=1 (queue active)
Jul 9 15:15:36 anake postfix/smtp[2082]: 02879340040: to=<hobXXson42@gmail.com>, relay=smtp.ntlworld.com[81.103.221.11]:25, delay=2.3, delays=0.1/0.02/2.1/0.13, dsn=5.0.0, status=bounced (host smtp.ntlworld.com[81.103.221.11] $
Jul 9 15:15:36 anake postfix/cleanup[2079]: 5370B340042: message-id=<20110709141536.5370B340042@anake>
Jul 9 15:15:36 anake postfix/bounce[2083]: 02879340040: sender non-delivery notification: 5370B340042
Jul 9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: from=<>, size=2228, nrcpt=1 (queue active)
Jul 9 15:15:36 anake postfix/qmgr[1293]: 02879340040: removed
Jul 9 15:15:36 anake postfix/local[2084]: 5370B340042: to=<www-data@anake.ianhobXXson.co.uk>, relay=local, delay=0.03, delays=0/0.02/0/0, dsn=2.0.0, status=sent (de开发者_JAVA百科livered to mailbox)
Jul 9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: removed
I do not understadn where it gets the "from" address from. The actual code executed is this:-
<?php
$to = 'hobXXson42@gmail.com';
$subject = 'Test email';
$message = 'hello - this has gone round the loop';
$headers = 'From: ian@ianhobXXson.co.uk' . "\n" .
'Reply-To: ian@ianhobXXson.co.uk' . "\n" .
'X-Mailer: PHP/'. phpversion()."\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Message sent OK";
} else {
echo "message send failed";
}
?>
Can anyone spot what is going wrong, and what I can do about it? Email addresses slightly munged in a rather obvious way. Ian
The "from" here is the envelope sender, i.e., the address which will end up in the Return-Path header. This header cannot be changed in the same way as other headers since this is not actually part of the mail but part of the envelope. Return-Path is the address which bounces is sent to, among other things.
You may be able to change the envelope sender by using the fifth argument of the mail()
function. Postfix (which your server is running), Sendmail and Exim all makes it possible to change the envelope sender using the -f
flag:
...
$extra_parameters = '-fian@ianhobXXson.co.uk';
mail($to, $subject, $message, $headers, $extra_parameters);
精彩评论