You are not logged in.

#1 2007-03-19 19:46:30

Intrepidus
Member
Registered: 2007-02-08
Posts: 54

How to send mail with php (how to set up a mail server, maybe?)

I know php has the ability to send mail, and I know how to do it. I've done it before on various hosting sites. However, those were their servers. Now I'm running Arch Linux as a server, and I want to send mail myself. I don't know how, though. Do I need to set up my own mail server? Will I have to recompile php with some funky bizarre options? Any help would be appreciated. I'm a bit new at this.

Offline

#2 2007-03-19 21:03:55

[vEX]
Member
From: Sweden
Registered: 2006-11-23
Posts: 450

Re: How to send mail with php (how to set up a mail server, maybe?)

You don't need to recompile PHP as far as I know, just set up a mail server locally and tell your PHP script to use it and it should work fine.

EDIT: The wiki describes how to install and set up Courier MTA - http://wiki.archlinux.org/index.php/Courier_MTA, not sure if it's the best choice or not, never had the need to set up a mail server, I do know though that Debian insisted at installing exim4 for mail stuff so that might be an alternative.

Last edited by [vEX] (2007-03-19 21:06:12)


PC: Antec P182B | Asus P8Z77-V PRO | Intel i5 3570k | 16GB DDR3 | GeForce 450GTS | 4TB HDD | Pioneer BDR-207D | Asus Xonar DX | Altec Lansing CS21 | Eizo EV2736W-BK | Arch Linux x86_64
HTPC: Antec NSK2480 | ASUS M3A78-EM (AMD 780G) | AMD Athlon X3 425 | 8GB DDR2 | GeForce G210 | 2TB HDD | Arch Linux x86_64
Server: Raspberry Pi (model B) | 512MB RAM | 750GB HDD | Arch Linux ARM

Offline

#3 2007-03-20 05:41:46

mezcal
Member
From: Czech Republic
Registered: 2006-01-31
Posts: 67
Website

Re: How to send mail with php (how to set up a mail server, maybe?)

Try ssmtp.

pacman -S ssmtp

and set  /etc/ssmtp/ssmtp.conf
It s the simplest MTA.

Offline

#4 2007-03-20 14:00:51

Intrepidus
Member
Registered: 2007-02-08
Posts: 54

Re: How to send mail with php (how to set up a mail server, maybe?)

I need to tell PHP about the server somehow, though, correct? I found a commented "sendmail_path", but am not entirely sure how to use it. Or will PHP automatically use ssmtp?

Offline

#5 2007-03-20 14:49:25

mezcal
Member
From: Czech Republic
Registered: 2006-01-31
Posts: 67
Website

Re: How to send mail with php (how to set up a mail server, maybe?)

No editing of the php.ini is needed.
Edit /etc/ssmtp/ssmtp.conf only.
The most important line is mailhub=.

Offline

#6 2007-03-20 16:01:47

Intrepidus
Member
Registered: 2007-02-08
Posts: 54

Re: How to send mail with php (how to set up a mail server, maybe?)

I'm still very confused by this. So I enter in the information, and point my forum at the SMTP address: test.mydomain, default port 25.

It tells me it can't connect to the smtp server.

If I leave the SMTP server information out, like the forum says (it says if there is no SMTP information, it will just use the local mailserver, which is what I want), I get the following in /var/log/httpd/error_log:

[Sun Mar 18 03:35:01 2007] [error] [client xxx.xxx.xxx.xxx] File does not exist: $
sh: /usr/sbin/sendmail: No such file or directory

Offline

#7 2007-03-21 06:31:55

mezcal
Member
From: Czech Republic
Registered: 2006-01-31
Posts: 67
Website

Re: How to send mail with php (how to set up a mail server, maybe?)

Ssmtp is not mail server. It only forwards mails to another mail server specified in mailhub.
mailhub=existing smtp server(it should not be on your computer)

If you want local mail server install postfix, exim, qmail etc.

Offline

#8 2007-03-25 00:14:35

arew264
Member
From: Friendswood, Texas, US
Registered: 2006-07-01
Posts: 394
Website

Re: How to send mail with php (how to set up a mail server, maybe?)

Okay, let me sum this up for you, and hopefully give you some understanding here.

What you want isn't a mail server. You want a SMTP server or MTA (mail transport agent).
PHP will connect to your SMTP server and use it to send emails.
Your ISP may provide a SMTP server, or you may have to set one up. I don't know if you have commercial internet (the high grade stuff people get to host servers) or plain residential. With plain residential (think Road Runner/Earthlink/SBC Yahoo), the ISP runs a SMTP server that is generally open for anyone from the inside to use.
When I say open, I mean you don't need any credentials/login info to send mail on tie ISP SMTP server.
If this is the case for you, just have PHP use that. It'll work just fine for sending mail anywhere you want.

If this is not the case or you need more help, let me know. I have had to set up a full blown mail server several times, and while it can be a PITA, I like to think I have some understanding and can help you.


EDIT: I should explain how PHP tries to send emails.

PHP, by default, tries to use sendmail to send email. This is because sendmail was a very old SMTP server and was very popular a few years back. Then it was discovered to be hugely insecure and everyone stopped using it.
However, the SMTP servers that replaced it began adding sendmail simulations that allowed programs written to use sendmail to continue working.

This is the source of your error invoving /usr/sbin/sendmail. PHP is trying to send mail using sendmail or a sendmail located at /usr/sbin/sendmail, and since none are there, it fails.

You can figure out if theres a sendmail simulation provided by ssmtp somewhere, or you can configure PHP to use ssmtp directly by figuring out how and where to give smtp server information. It can be done, you just have to find how to do it (I haven't used PHP to send mail on my home server, so I don't know how/where you do it, sorry).

The third and most painful option is to change SMTP servers. You're free to do this, I recommend Postfix (pretty easy to figure out and very reliable). However, this is the option you probably don't want to take.

Last edited by arew264 (2007-03-25 00:21:13)

Offline

Board footer

Powered by FluxBB