Send emails using PHP mail function, configuration of the mail server - php

I am making a web application (html + php + apache + mysql) which is on a Debian server, but when I try to send any mail using the php mail function, it is not simply sent me and throws an error. I guess I should install some smtp mail service. What do you recommend that is easy for a novice user settings?
I install a library called sendmail in localhost that simulates that smpt service in WAMP server, but when I upload the code to the production server simply does not send mail.
I researched on some mail servers like postfix, but the information I get is confusing to me. I want to recommend me some effective guide, or any server that is easy to configure for a novice user in the subject.
sorry if the question is obvious, but I want effective information

For sending a mail you just simply need a smtp client that sends a mail to a destination. You don't need to install any smtp server for just sending a mail.
A smtp server is for receiving mails( and other stuff about mails).
All you need to make php sending a mail is to install a smtp client like sendmail
then edit php.ini to be like this:
sendmail_path= sendmail -t -i
EDIT: I guess debian has sendmail by default.

Related

mail() not working on my virtual machine

Mail() is not working on my virtual machine.
I would like to use it for my php application. What can I do?
What settings should I configure in php.ini to have it work>
I am using sendmail and when I look at the mail logs it tells me "Connection timeout" what can I do?
Also when I do from terminal on my centos server:
telnet smtp.gmail.com 25
it blocks and doesn't output anything.
You need to setup a mail server on your machine for the mail function to work. If you are on Windows (which I am guessing) you can setup a Pegasus mail server. Connecting to either your ISPs SMTP server or GMail or whatever is the easiest route out of this one.
You need to define SMTP settings in your php.ini to talk to a mail server through which you are allowed to send outbound messages, with or without authentication.
If you are working from wamp or xamp then u have to pear mail or some other library to support your configuration. I used pear http://pear.php.net/package/Mail/ ...... it will also contain test mail sending tutorial

Send email from php application through a separate email server running postfix

I recently setup a CentOS server that I am planning on using just for email. I installed and configured Postfix and sending / receiving messages via command-line is working fine.
I want to be able to send mail to my end-users from a PHP application that is hosted on a separate CentOS server, using the dedicated mail server's Postfix as the MTA. Is this possible? Or do I need to install Postfix on the server where Apache / PHP resides?
If it is possible, how do I go about connecting / relaying the messages that are to be sent?
I am looking for the common conventions / best practices for running my own mail server, so any advice is much appreciated. Thanks!
If you use mail() in PHP, the documentation states that it only uses sendmail on the local machine.
You may, however, setup sendmail to forward mail to your other server, like in this link : http://www.cyberciti.biz/faq/configure-sendmail-as-a-smart-host/
According to that page, you can do this:
Add to /etc/mail/sendmail.mc:
define(`SMART_HOST',`my_smtp_server')
Then restart sendmail. If it still doesn't work, you might need to run:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
or
cd /etc/mail; make
and then restart sendmail.
If you need to fake the server name which sendmail uses, you might add this in sendmail.nc (ref.: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-email-mta-sendmail.html):
FEATURE(always_add_domain)
FEATURE(`masquerade_entire_domain')
FEATURE(`masquerade_envelope')
FEATURE(`allmasquerade')
MASQUERADE_AS(`my_public_domain.')
MASQUERADE_DOMAIN(`my_public_domain.')
MASQUERADE_AS(my_public_domain)
You can configure postfix as MTA on the same server on which php/apache resides if you keep it remote you have to ensure proper connectivity to MTA and due to any timeout issue your mails might not get delivered. So you can run postfix on the local apache/php server and configure it's settings with php to send email.
http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm
The above link would be helpful.
Thanks & Regards,
Alok Thaker

Mail function - change SMTP relay

I use PHP's mail function to send emails from my server, which currently also handles mail. However, I would like PHP to start sending messages through a different SMTP relay, not the server it's running on. I checked out php.ini, and it appears that it is only possible to specify a different relay on a Windows PC, whilst my server is running OS X Snow Leopard. Is it possible to change the relay settings? Ideally, I wouldn't want to incorporate anything new into my PHP code, as I use the mail function all over the place.
You cannot do this without either setting up a sendmail alternative on your server that routes mail through SMTP, or much much easier, using a library like Swiftmailer.
PHP does not have the capability to use an external SMTP server built in (Unless you are on a Windows platform).

Use default PHP mail function with SMTP server on Linux

I am working on a php/c# project which is an Email Server with a web interface to manage the Email Server application.
The program is supposed to work on windows and linux but I have been mostly doing my development in windows.
I've not come onto testing in Linux and have found a horrible problem.
From what I have googled on Windows PHP you can choose an SMTP server that you want to use, but it looks as if on Linux you don't have this option so when PHP sends an email it completely bypasses my program.
Is there a way to make PHP use an SMTP server of your choice, I know you can use PEAR to overrride the SMTP settings but I'd prefer that the standard PHP mail function would work so other software like PHPBB forum would send emails via my SMTP server instead of the default php mail.
Is this something that is possible or is my only option to use pear?
You standard php mail function will just send to whatever is defined as the sendmail _path in php.ini
This is typically sendmail -t -i
You would need to configure sendmail to use smtp.
FWIW, most developer who do a lot of mail sending from PHP apps revile the mail() and instead use one of many mailing libraries (or services) which provide better configurability/reliability.
You could for example pipe the mail function to your own PHP script and use whatever library you wanted to in that script in order to do mail sending (and thus preserving the use of mail() function across applications).

PHP: how to send email basics

I'm would like to use PHP to send email from my localhost to other people. What do I need to do that?
For example do I need to install mailserver? If I'm not mistaken there's is a language that you don't need a mailsever to send email. Is it right?
Inside the PHP.ini, there is [mail function]. How to configure this? I checked on the Internet, but do not really understand how it works.
[mail function] ; For Win32 only.
SMTP = localhost
smtp_port = 25
sendmail_from =admin#localhost.com //Not sure how to write this?
You would have to set up a local mail server if you want to send mail using the mail() function. You can't use a remote mail server as the php mail() function does not allow you to specify authentication credentials. However, I have found setting up a local mail server tedious and annoying, in addition it can be dangerous. I recommend looking into PHPMailer. It is simple to use and get running.
You need the software that will actually send the email after your PHP script has made a request to so (through using the mail function: http://php.net/mail). As stated in some of the previous responses there are software options for this, regardless of what operating system you run.
This, however, can sometimes be quite tricky for a beginner. Typically your ISP will give you access to an SMTP server from which to send emails, and you can set up your configuration to do this. For development purposes, this ought to do the trick for you. These details will likely be on your ISP's website (or possibly in your email client, somewhere.) Your config would end up looking something like
[mail function] ; For Win32 only.
SMTP = smtp.my-isp.com
smtp_port = 25
sendmail_from =my.account#my-isp.com
Failing that, you could just upload your script to your web host, where it should already be configured to work.
Hope that helps.
mail("recipient#domain.com", "Subject", "This is an email!");
You just need to install some email server. If you are on linux, you can try exim, if you are on windows, you can use the SMTP server that comes with IIS.
Yes, you do need a mail server available. PHP's mail() function accepts the information you give it and passes it off to the mail server for delivery. PHP doesn't deliver mail itself.
What mail server you use depends on what operating system you are using. Traditionally on unix-type machines there will be an installation of sendmail or some other service running. On Windows, you can specify the name of an SMTP server in the php.ini configuration file.
phpmailer is a good choice.
you can google it for details.
Actually, email is sent using socket.
The simple way is by using the mail() command. On Linux it's a pipe to sendmail binary and on Windows, I don't know, probably it use some Microsoft voodoo library.
Anyway, I strongly recommend to use phpMailer because it's a mature project, really stable, easy to setup, with a lot of features and it also includes an SMTP and IMAP client implementation, so absolutely cross-platform.
Anyway, you should consider to use anyway a local SMTP server as first hop to handle the mail queue in case of network failure.
There is no need for an installation of a special module to have access to mail functions in PHP.
But For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following:
/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib.
It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.
If you are working on a linux environment using a hosting provider is most likely that the sendmail is already present, otherwise you can check from a terminal doing:
cat some_file.txt |mail -s "test mail" user#yourmail.com

Categories