PDA

View Full Version : sendmail not working with PHP


wintertong
26th February 2009, 11:48
Hi,

Can anyone help?

I have installed a new Ubuntu Server which is running Apache, MYSQL and PHP.

This server is not a mail server so I have changed my PHP.ini file to use the remote smtp server on port 25. I have saved this and restarted apache / php so that the changes take effect. I can see that they have been set in phpinfo.

The sendmail is being called from /usr/sbin/

I am calling the php function mail() which in turn runs sendmail. This was erroring with "sendmail: fatal: open /etc/postfix/main.cf: No such file or directory".

So I went into /etc/postfix/ and main.cf does not exist. I have these files in there:

-rw-r--r-- 1 root root 318 2009-02-24 19:20 dynamicmaps.cf
-rw-r--r-- 1 root root 4300 2009-02-24 19:20 master.cf
-rw-r--r-- 1 root root 18231 2008-09-03 15:28 postfix-files
-rwxr-xr-x 1 root root 7421 2008-09-03 15:28 postfix-script
-rwxr-xr-x 1 root root 22774 2008-09-03 15:28 post-install
drwxr-xr-x 2 root root 4096 2008-09-03 15:28 sasl

I assumed that I could take a copy of master.cf and call it main.cf Is this correct?

It did not work as now it says "sendmail: fatal: /etc/postfix/main.cf, line 22: missing '=' after attribute name: "smtp inet n - - - - smtpd". I do not know enough about this to fatham out what is wrong.

Help Please?!!

Is there something basic that I have forgot? Any help would be much appreciated.


Regards Gareth

topdog
27th February 2009, 09:59
master.cf and main.cf have different formats you need an actuall main.cf file.
Try extracting it from the debian package. or setup a working one.

wintertong
27th February 2009, 11:36
Thanks for this, I now have this main.cf file:

I ran this "aptitude install postfix" and then dpkg-reconfigure postfix. I ended up with a main.cf below.

I created a simple mail() php file and this time it did not error. It still did not send and email though.

# 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 (Ubuntu)
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 = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.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 = server53009.uk2net.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = noreply@studio2online.co.uk, server53009.uk2net.com, localhost.uk2net.com, localhost
relayhost = 83.170.96.113
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 10
recipient_delimiter =
inet_interfaces = loopback-only
inet_protocols = all

topdog
27th February 2009, 11:50
What errors do u see in the logs ?

wintertong
27th February 2009, 11:53
There are no errors in the /opt/lampp/logs/error_log

Has postfix got its own error log? Sorry, never setup sendmail before. Always been installed ready.

topdog
27th February 2009, 11:55
Yes postfix has its own log file usually /var/log/maillog

wintertong
27th February 2009, 11:55
I have just tried going to /usr/sbin/ and ran sendmail -t gareth.winterton@gmail.com -i test

This just hung

wintertong
27th February 2009, 11:57
Feb 27 09:57:30 server53009 postfix/pickup[23864]: 0E94A4CE5F2: uid=65534 from=<nobody>
Feb 27 09:57:30 server53009 postfix/cleanup[23873]: 0E94A4CE5F2: message-id=<20090227095730.0E94A4CE5F2@server53009.uk2net.com>
Feb 27 09:57:30 server53009 postfix/qmgr[6571]: 0E94A4CE5F2: from=<nobody@noreply@studio2online.co.uk>, size=399, nrcpt=1 (queue active)
Feb 27 09:57:30 server53009 postfix/smtp[23875]: 0E94A4CE5F2: to=<gareth.winterton@s2o.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.03, delays=0.02/0/0/0, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] said: 501 5.5.4 Syntax error in parameters scanning (in reply to MAIL FROM command))
Feb 27 09:57:30 server53009 postfix/cleanup[23873]: 13FD44CE5F3: message-id=<20090227095730.13FD44CE5F3@server53009.uk2net.com>
Feb 27 09:57:30 server53009 postfix/bounce[23876]: 0E94A4CE5F2: sender non-delivery notification: 13FD44CE5F3
Feb 27 09:57:30 server53009 postfix/qmgr[6571]: 13FD44CE5F3: from=<>, size=2360, nrcpt=1 (queue active)
Feb 27 09:57:30 server53009 postfix/qmgr[6571]: 0E94A4CE5F2: removed
Feb 27 09:57:30 server53009 postfix/smtp[23875]: 13FD44CE5F3: to=<nobody@noreply@studio2online.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.03, delays=0.02/0/0/0.01, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] said: 501 5.5.4 Syntax error in parameters scanning (in reply to RCPT TO command))
Feb 27 09:57:30 server53009 postfix/qmgr[6571]: 13FD44CE5F3: removed

topdog
27th February 2009, 11:59
As you can see from the logs your PHP script is sending an incorrect email address

wintertong
27th February 2009, 12:07
Hi,

It looks like that dont it but this is my php script:

<?php

$Name = "Gareth Winterton"; //senders name
$email = "gareth.winterton@gmail.com"; //senders e-mail adress
$recipient = "gareth.winterton@s2o.co.uk"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)

?>

and the error is still here. Do you think that it could be something in the php.ini file?

Feb 27 10:05:04 server53009 postfix/pickup[23864]: 8EA1B4CE5F2: uid=65534 from=<nobody>
Feb 27 10:05:04 server53009 postfix/cleanup[24053]: 8EA1B4CE5F2: message-id=<20090227100504.8EA1B4CE5F2@server53009.uk2net.com>
Feb 27 10:05:04 server53009 postfix/qmgr[6571]: 8EA1B4CE5F2: from=<nobody@noreply@studio2online.co.uk>, size=366, nrcpt=1 (queue active)
Feb 27 10:05:04 server53009 postfix/smtp[24055]: 8EA1B4CE5F2: to=<gareth.winterton@s2o.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.05, delays=0.04/0/0/0, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] said: 501 5.5.4 Syntax error in parameters scanning (in reply to MAIL FROM command))
Feb 27 10:05:04 server53009 postfix/cleanup[24053]: 99FB94CE5F3: message-id=<20090227100504.99FB94CE5F3@server53009.uk2net.com>
Feb 27 10:05:04 server53009 postfix/qmgr[6571]: 99FB94CE5F3: from=<>, size=2327, nrcpt=1 (queue active)
Feb 27 10:05:04 server53009 postfix/bounce[24056]: 8EA1B4CE5F2: sender non-delivery notification: 99FB94CE5F3
Feb 27 10:05:04 server53009 postfix/qmgr[6571]: 8EA1B4CE5F2: removed
Feb 27 10:05:04 server53009 postfix/smtp[24055]: 99FB94CE5F3: to=<nobody@noreply@studio2online.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.03, delays=0.02/0/0/0.01, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] said: 501 5.5.4 Syntax error in parameters scanning (in reply to RCPT TO command))
Feb 27 10:05:04 server53009 postfix/qmgr[6571]: 99FB94CE5F3: removed

wintertong
27th February 2009, 12:09
This was taken from my php.ini file

[mail function]
; For Win32 only.
SMTP = 83.170.96.113
smtp_port = 25

; For Win32 only.
sendmail_from = noreply@studio2online.co.uk

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i

Should I remove the win32 bits? I assume so.

topdog
27th February 2009, 12:13
Postfix is trying to qualify the name because it gets it as the web server user nobody what is in this file /etc/mailname

topdog
27th February 2009, 12:14
yes remove them that is where the qualification part is coming from.

wintertong
27th February 2009, 12:17
noreply@studio2online.co.uk is in mailname

I have removed the win32 bits and restarted php / apache.

still getting same error

topdog
27th February 2009, 12:20
comment this myorigin = /etc/mailname out from your postfix main.cf file restart postfix and apache and test again.

wintertong
27th February 2009, 12:29
Hi,

Did you mean add the # or remove the # from that line in the main.cf? It already had the # in there so I removed it. Restarted postfix by doing /etc/init.d/postfix restart and restarted apache / PHP.

Ran email script and still got

Feb 27 10:23:46 server53009 postfix/pickup[24776]: A1F594CE5F2: uid=65534 from=< nobody>
Feb 27 10:23:46 server53009 postfix/cleanup[24784]: A1F594CE5F2: message-id=<200 90227102346.A1F594CE5F2@server53009.uk2net.com>
Feb 27 10:23:46 server53009 postfix/qmgr[24777]: A1F594CE5F2: from=<nobody@norep ly@studio2online.co.uk>, size=366, nrcpt=1 (queue active)
Feb 27 10:23:46 server53009 postfix/smtp[24786]: A1F594CE5F2: to=<gareth.wintert on@s2o.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.03, delays=0.03/0/ 0/0, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] said: 501 5.5. 4 Syntax error in parameters scanning (in reply to MAIL FROM command))
Feb 27 10:23:46 server53009 postfix/cleanup[24784]: AB1914CE5F3: message-id=<200 90227102346.AB1914CE5F3@server53009.uk2net.com>
Feb 27 10:23:46 server53009 postfix/qmgr[24777]: AB1914CE5F3: from=<>, size=2327 , nrcpt=1 (queue active)
Feb 27 10:23:46 server53009 postfix/bounce[24787]: A1F594CE5F2: sender non-deliv ery notification: AB1914CE5F3
Feb 27 10:23:46 server53009 postfix/qmgr[24777]: A1F594CE5F2: removed
Feb 27 10:23:46 server53009 postfix/smtp[24786]: AB1914CE5F3: to=<nobody@noreply @studio2online.co.uk>, relay=83.170.96.113[83.170.96.113]:25, delay=0.02, delays =0.01/0/0/0.01, dsn=5.5.4, status=bounced (host 83.170.96.113[83.170.96.113] sai d: 501 5.5.4 Syntax error in parameters scanning (in reply to RCPT TO command))
Feb 27 10:23:46 server53009 postfix/qmgr[24777]: AB1914CE5F3: removed

topdog
27th February 2009, 12:32
I meant add a # and if you have not noticed you have two of the same line in your config file one commented out and the other not. you need to have a # infront of both

wintertong
27th February 2009, 12:38
Your the dude!!!! Thanks, it is now sending emails! Really appreciated