I'm trying to get an in-house bugtracking software up and running. Most of them are written in PHP, which our live server isn't set up for, and the ASPX trackers I've found won't work either, because our live server is running decade-old installs of its server software and upgrading it breaks two other sites we host for clients.
So I've been turning an old rendering machine (Windows XP) into a intranet server I can throw in the basement. I'd install Linux...if a) reinstalling an OS wasn't a full-day job and b) if anyone in the office was actually familiar with Linux
Anyway. I've got WAMP installed and working just fine (one minor issue that the "put on/offline menu item doesn't work, but I can manually change the configs) and Mantis is set up and ready to go, except for one thing.
Mantis can't send emails.
I've tried literally a dozen different ways of doing things: using gmail, using our own relay server, using a "fake" sendmail thing, and various config options between Mantis, PHP, and sendmail.
Nothing works and I am given remarkably little feedback on where the operation is failing.
Is there something I'm missing? I had one person suggest that I needed to install Window's SMTP service (I will need to dig up and/or burn a Windows XP disc). Only one guide mentioned enabling PHP's OpenSSL (but didn't say if that needed to be configured or how).
You might use "fake sendmail".
Most people use this tool to write emails to disk for testing purposes, but
the tool allows forwarding of emails to your SMTP server.
Download: http://www.glob.com.au/sendmail/sendmail.zip
Configure fake sendmail in "sendmail.ini" to contain your SMTP credentials
test sendmail on the CLI and check your SMTP account for outgoing mails
Configure php.ini (directive "sendmail_path")
sendmail_path = "sendmail.exe -t"
test mail() function from a PHP script
Config Files:
sendmail.ini:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=****#gmail.com
auth_password=*******
force_sender=****#gmail.com
php.ini:
sendmail_path = "\"C:\sendmail\sendmail.exe\" -t"
As it tuns out, my problem was resolved by simply using a different relay server. For some reason Verizon decided to just "nope" without saying why (not that PHP gets much in the way of error messages with email anyway).
http://mandrill.com/ offers a free SMTP service (for the first 12,000 emails per month you send) and as soon as I started using it, bam, everything worked.
I didn't need sendmail (using PHP_SMTP not PHP_SENDMAIL or PHP_MAIL in my MantisBT options) although may be required for other people.
Related
I am maintaining an old PHP application and I would like to configure it to use Mandrill for outgoing email. Mandrill, of course, requires SMTP authentication. The application uses PHP's mail() function directly.
Is there any way I can configure sendmail (or an equivalent service) to send using SMTP authentication by default (with the credentials for Mandrill), without having to replace all the mail() calls throughout the application?
I saw some other answers about SMTP configuration in php.ini but that only works on Windows, so I believe the only PHP setting I could change that would potentially be useful is sendmail_path, which defaults to sendmail -t -i. I was thinking maybe I could point it to a shell script instead but I'm not sure how to go about that or whether it would work.
UPDATE
Thanks to #mti2935's answer, I was able to get this working. I had trouble getting sSMTP to work (got the error "send-mail: Cannot open smtp.mandrillapp.com:587" even though there was no firewall blocking it) so I followed the second link and set up MSMTP. I had to change the tls_trust_file setting to /etc/pki/tls/certs/ca-bundle.crt (note: I'm running CentOS 6). Also, the sendmail_path PHP setting recommended in the link didn't work for me; I had to change it to "/usr/bin/msmtp -C /etc/msmtp/myconfig -t" (and restart Apache since I changed this in php.ini rather than in an .htaccess file...note that the config file can be called whatever you want; choose your own name in place of "myconfig").
Also, when testing, be sure to specify a "From" address, otherwise some destinations including Gmail might reject the message.
There are a number of lightweight replacements for sendmail that can be used to relay outgoing messages through a remote SMTP relaying server, such as SSMTP, MSMTP, and Nullmailer. By replacing /usr/sbin/sendmail with one of these, you can relay outgoing mail sent from your PHP scripts through a remote SMTP server, without making any changes to your PHP scripts that use the PHP mail() function. These replacements simply handoff the message to the relaying server - the don't handle incoming mail, they don't manage a queue, etc.
See:
http://itekblog.com/ssmtp-a-gmail-sendmail-relay-replacement-for-linux/
http://www.emanueletessore.com/how-to-configure-msmtp-as-a-gmail-relay-on-ubuntu-server/
http://untroubled.org/nullmailer/
Another option may be to continue using sendmail, configured with a smarthost. See https://serverfault.com/questions/41448/fastest-way-to-allow-sendmail-relay-through-smarthost
Swiftmailer is a good option. You should also take a look at Zend2 Mail. I used this on a small project and it fit the bill nicely.
PHP Storm has a pretty cool search and replace function. If you just search for let's say "mail(" (without the quotes) you can manually go through the results and confirm before replacing them. Or you can do a replace but before it replaces each occurrence, you can confirm it.
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
I'm looking for an SMTP server that I can setup on a windows machine:
It needs to be lightweight, not loads of security settings
I only need to send email not receive it
Its needs to be able to send email from anonymous users
The reason is that I've installed Apache and PHP on a windows machine and want an SMTP server to route mails through, I plan on using this windows sendmail.exe which I have used before and works great.
Last time I did this I used sendmail.exe and Stunnel and used a gmail address, but I can't do that this time, needs to be sent from localhost.
You could use the SMTP server integrated in IIS, you could also go for smaller mail servers like http://www.xmailserver.org/ or http://www.mailenable.com/
Too bad, stunnel/gmail is great and I've used it a ton for test environments.
Two great alternatives are to install exim via Cygwin, or to use IIS as an SMTP server.
I have personally used the first with success. I have never tried IIS although I know this is a viable solution for some.
I'm developing a Web application with PHP 5.3.3.
I want it to send confirmation e-mails automatically.
I don't have a domain name yet.
I'm using Windows XP.
I don't have PEAR's Mail package.
I have hMailServer and is the mail server I want to use to send the e-mails.
My questions are:
Can I send e-mails without a domain name? (Is it absolutely necessary? I just want to test the application for the moment.)
If a domain name is necessary, do I also need to host the application with a Web Hosting Service Provider? Can I do it from my computer?(Remember, I just want to test the application.)
Do I absolutely need the PEAR's mail package? or can I simply use the mail() function?
I'm clueless about what I should do. I've made my research, I understand the parts but I can't make sense of the whole, I mean what resources are necessary and how to put it together. I've never developed any application that sends e-mail before. Please, help me.
Yes. You can set your "from" address to whatever you want. (Though note, the recipient server might detect it's forged and reject it.)
You can host from you computer, just make sure your network is not blocking port 25 outbound.
mail() alone will suffice as long as you have a local SMTP server that will handle your messages. (I'm assuming that's what the hMailServer product is.)
First off, if you're running Windows as your server, you need to configure how your e-mails will be sent (SMTP server). Go to this section in your php.ini file. Change localhost to an SMTP server you can use from your network (either the IP address of your hMailServer OR sometimes you need to purchase one to use like http://www.smtp2go.com/).
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Second, you use the mail(...) function in php (including the ability to send HTML mail). That's it.
Yes, you can. I believe your emails will show up with your server's DNS by default, but you can set the from: header to whatever you want. However, if you change the from: header, be warned that your emails are likely to get picked off by spam filters.
You need some special server configuration to use the php mail() function - I haven't tried setting it up myself, but I know that a basic local apache / php install won't have the capacity to send emails. Pretty much every paid web server should have it set up properly, though.
No. You can send regular and html emails with the generic mail() function.
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