# qmail send two identical mails via php mail() [qmail-inject]



## mxm (Sep 30, 2009)

Sorry for my english and i'm learning using Freebsd 6.0 so i have no idea where i may search for errors in configuration files.

THE PROBLEM:
I have uninstall sendmail and i've instaled qmail on FreeBSD to send messages via PHP function: mail(). 
In php.ini i have:

```
sendmail_path = /var/qmail/bin/qmail-inject
```
This configuration sends e-mail but i've got on my mailbox (different host) two identical mails. Why??
The PHP script is working fine on windows with smtp server so it's ok.

I have no idea where to start looking...

Looking forward to getting an answer


----------



## DutchDaemon (Sep 30, 2009)

You _uninstalled_ Sendmail? You actually removed it from the base system? And you installed qmail in such a way that it ends up in _/var/qmail_? Have you read The Handbook? I wonder if anyone can (or will) help you with a severely outdated version of FreeBSD and a non-standard (de)installation of software.


----------



## mxm (Sep 30, 2009)

Yes i uninstall sendmail brutaly. I've chenaged line in rc.conf file 'sendmail_enable="NO"' and i've deleted the main running file 'sendmail' from somewhere (dont remember). But i'm sure sendmail isn't working (when system starts i got errors with 'i can't find sendmail' or something). Next i've moved 'sendmail' files from /usr/lib and /usr/sbin to files 'sendmail.bak'. 

I didnt read The Handbook becouse where is nothing about qmail. But I've read this: freebsddiary.org/qmail.php exept installing qpopper. For now I only want to have SMTP server localy to send e-mail from PHP.


----------



## dennylin93 (Oct 1, 2009)

I think you're in a complete mess. Read the ports section in the Handbook and then the section about MTAs. Next time, install qmail using ports since it's a better option.


----------



## mxm (Oct 1, 2009)

i've installed qmail from ports: 'make install clean' with no special configure options (default).


----------



## dennylin93 (Oct 1, 2009)

Oops. I just looked at the port and found out that it does install to /var/qmail by default. Usually files are installed to /usr/local.

Take a look at /var/log/maillog and see why it's being sent twice.


----------



## mxm (Oct 1, 2009)

from */var/maillog*: 
	
	



```
Oct  1 08:37:56 server qmail: 1254386276.229893 new msg 260
Oct  1 08:37:56 server qmail: 1254386276.230811 info msg 260: bytes 1049 from <anonymous@server.domain.com> qp 4547 uid 1004
Oct  1 08:37:56 server qmail: 1254386276.356553 starting delivery 5: msg 260 to remote my_mail@o2.pl
Oct  1 08:37:56 server qmail: 1254386276.378653 status: local 0/10 remote 1/20
Oct  1 08:37:56 server qmail: 1254386276.401454 starting delivery 6: msg 260 to remote my_mail@o2.pl
Oct  1 08:37:56 server qmail: 1254386276.402124 status: local 0/10 remote 2/20
Oct  1 08:37:56 server qmail: 1254386276.668155 delivery 6: success: 193.17.41.214_accepted_message./Remote_host_said:_250_OK_queued_as_nbjSvA/
Oct  1 08:37:56 server qmail: 1254386276.669026 status: local 0/10 remote 1/20
Oct  1 08:37:56 server qmail: 1254386276.871102 delivery 5: success: 193.17.41.123_accepted_message./Remote_host_said:_250_OK_queued_as_hnthXK/
Oct  1 08:37:56 server qmail: 1254386276.872193 status: local 0/10 remote 0/20
Oct  1 08:37:56 server qmail: 1254386276.872827 end msg 260
```


----------



## dennylin93 (Oct 2, 2009)

I can't really see any problems from the log. Check your PHP script to see if you accidentally configured it to send mail twice.


----------



## mxm (Oct 2, 2009)

Yep. The script was the problem but why??

I wrote some simple script test:

```
<?php
	// Headers
	$naglowki = 'MIME-Version: 1.0' . "\r\n";
	$naglowki .= 'To: [email=my_mail@o2.pl]my_mail@o2.pl[/email]'."\r\n";
	$naglowki .= 'From: Me <no-reply@no-reply.pl>' . "\r\n";				
	// Subject
	$temat = 'Testing';
	// Message
	$wiadomosc = "TEST";
	// Sending
	if( ! @mail([email='my_mail@o2.pl]'my_mail@o2.pl[/email]', $temat, $wiadomosc, $naglowki))
		die('Sorry...');
?>
```
 The same. I've got two identical mials in log.

And other simple script without headers:

```
<?php
	// Sending
	if( ! @mail([email='mxm_one@o2.pl]'mxm_one@o2.pl[/email]', "Subject", "TEST"))
		die('Sorry...');
?>
```
 Yep. Only 1 message in box.

So I've got question why i can't use headers in qmial via PHP mail() function?? Qmail isn't good for PHP??


----------



## J65nko (Oct 2, 2009)

The online man page is http://www.ezmlm.org/man/man8/qmail-inject.8.html
This refers to http://www.ezmlm.org/man/man5/qmail-header.5.html which states





> RECIPIENT ADDRESSES
> 
> qmail-inject looks for recipient address lists in the following fields: To, Cc, Bcc, Apparently-To, Resent-To, Resent-Cc, Resent-Bcc.



How do the full mail headers look like as received by the recipient?


----------



## dennylin93 (Oct 3, 2009)

mxm said:
			
		

> Yep. The script was the problem but why??
> 
> I wrote some simple script test:
> 
> ...



This should be unrelated to qmail although I'm not completely sure. I'm hopeless at PHP right now, but how about removing the "To" header?

```
// Headers
	$naglowki = 'MIME-Version: 1.0' . "\r\n";
	$naglowki .= 'From: Me <no-reply@no-reply.pl>' .
```

Try and see if it works.


----------



## mxm (Oct 4, 2009)

I've done some tests. So if u want have header: "To: ...@..." u must use function mail() without address in first argument. Example:

```
<?php 
    // Headers 
    $naglowki = 'MIME-Version: 1.0' . "\r\n"; 
    $naglowki .= 'To: [email=my_mail@o2.pl]my_mail@o2.pl[/email]'."\r\n"; 
    $naglowki .= 'From: Me <no-reply@no-reply.pl>' . "\r\n";                 
    // Subject 
    $temat = 'Testing'; 
    // Message 
    $wiadomosc = "TEST"; 
    // Sending 
    if( ! @mail('', $temat, $wiadomosc, $naglowki)) 
        die('Sorry...'); 
?>
```
Of course the example above is also a good move.

So the problem is SOLVED


----------

