# Sendmail and PHP - configuring sendmail/PHP



## c00kie (Apr 20, 2013)

*H*i,

I'm trying to use mail() in a PHP script residing on my FreeBSD server; only it appears I have problems with Sendmail. It's not an error in my script; I know this for sure from close inspection and testing, i.e. my variable is set to true. I've had Sendmail working previously and was accessing my messages from the terminal. And currently:

`$ mail`

```
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/1cookie": 2 messages 1 new
    1 root@my.domain.or  Sun Nov  4 05:07  30/1138  "Nvi saved the file vi.5668mU6CyE"
>N  2 root@my.domain.or  Thu Dec 27 11:00  29/1115  "Nvi saved the file vi.5668mU6CyE"
```

I don*'*t see any reason why it should suddenly stop, maybe you could show me how to access mailbox /etc/mail/fred say and read messages for this user? I really lack experience.


```
$ cd /var/mail
$ ls
1cookie	ftp	mysql	root	tqadmin	www
```

Are the above the mailboxes on my system?

My PHP/Server configuration goes like:

`$  which sendmail`

```
/usr/sbin/sendmail
```

/usr/local/etc/php.ini

```
sendmail_path = /usr/sbin/sendmail
```

As far as I know my user tables, hosts, and aliases are set up correctly. Here's a brief snapshot of my configuration:

/etc/mail/virtusertable

```
admin@mydomain.org	andy
```

/etc/mail/local-host-names

```
mydomain.org
localhost
admin.mydomain.org
```

/etc/mail/aliases

```
root: me
# NETWORK OPERATIONS MAILBOX NAMES
abuse:	root
# noc:		root
security:	root
admin:		root
```

And it isn't a firewall issue as I've opened the ports Sendmail is currently configured to listen on.

Further investigation:

`$  service sendmail status`

```
sendmail is not running.
sendmail_clientmqueue is running as pid 45547.
```

It would appear Sendmail is not running? I can't even start it:


```
# cd /etc/mail make start
# make start
```


```
Starting: sendmail554 5.3.5 /etc/mail/sendmail.cf: line 278: Unknown address family inet6 in Family=option
 sendmail-clientmqueue.
```

And finally but not exhaustive:

`# service sendmail rcvar`

```
# sendmail
#
sendmail_enable="YES"
#   (default: "")

# sendmail_clientmqueue
#
sendmail_enable="YES"
#   (default: "")
sendmail_msp_queue_enable="YES"
#   (default: "")
```

So the daemon is set to run by default.

I've got root access to my VM but little experience and even littler support. 




Other stuff I've tried:


```
$ mail -v -s "Test email" [email]myemail@yahoo.com[/email] 
[enter]                                                              
This is a test email [enter]
. [enter]
```

The terminal returns:

```
EOT
myemail@yahoo.com... Connecting to [127.0.0.1] via relay...
myemail@yahoo.com... Deferred: Connection refused by [127.0.0.1]
```

I checked /var/log/maillog and I'm receiving lots of messages of this nature:

```
Apr 21 05:57:56 web sm-msp-queue[49019]: r3GF9iZe033456: to=root, ctladdr=root (0/0), delay=4+18:48:12, 
xdelay=00:00:00, mailer=relay, pri=28267819, relay=[127.0.0.1], dsn=4.0.0, 
stat=Deferred: Connection refused by [127.0.0.1]
```

Then:

```
# cd /etc/mail 
# make start
Starting: sendmail554 5.3.5 /etc/mail/sendmail.cf: line 278: Unknown address family inet6 in Family=option
 sendmail-clientmqueue.
```

Help


----------



## c00kie (Apr 21, 2013)

*solved*

It turns out the solution to this problem was:

Sendmail was not starting on my system because of an IPv6 option on line 278 of /etc/mail/sendmail.cf. So comment out that line.

That then left lots of 
	
	



```
savemail: cannot save rejected email anywhere
```
 messages when starting Sendmail; this was because of an alias in /etc/aliases pointing root's mail to user1, say. Solution: delete that line.

The product of all this is I am now able to send a test email out and it seems to be delivering to outside mail hosts.


----------



## wblock@ (Apr 21, 2013)

Please, please do not edit the .cf files directly, they will be overwritten when you build the sendmail config as recommended, from the _hostname_.mc file.  See /etc/mail/Makefile.


----------



## c00kie (Apr 22, 2013)

wblock@ said:
			
		

> Please, please do not edit the .cf files directly, they will be overwritten when you build the sendmail config as recommended, from the _hostname_.mc file.  See /etc/mail/Makefile.



Thanks

I'm trying to get Sendmail to accept mail from an external host myaccount@yahoo.com.

I would also like to have a couple of mailboxes on the server, admin and me say. Could you point me to a good tutorial. I'm reading the manual but not having much success. Upon trying to send mail from Yahoo to my server, Yahoo reports:

```
Sorry, we were unable to deliver your message to the following address.

<admin@mydomain.org>:
Remote host said: 550 5.1.1 <admin@mydomain.org>... User unknown [RCPT_TO]
```


----------



## fonz (Apr 28, 2013)

c00kie said:
			
		

> Could you point me to a good tutorial. I'm reading the manual but not having much success.


If by manual you didn't mean the FreeBSD Handbook, then said handbook has a section on setting up mail.


----------

