Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is there anyway to force everytime the PHP Mail() is used to force it to use SMTP authentication?

Maybe a setting through the PHP.ini file or a server configuration?

share|improve this question
    
Why are you asking? For example, this is a problem for WordPress if the server doesn't allow mail(), but there's a plugin to handle the situation. (Your answer might also affect where/whether the question gets migrated.) –  Su' Dec 27 '11 at 20:24
    
Well wordpress does have a plugin to force SMTP and it seems to work so far. But there's all sorts of PHP scripts out there that use the default Mail(). Instead of having to change them every time it'd be nice to be able to configure an SMTP Amazon server and use that every single time the PHP mail() is used. It would be a billion times more reliable. –  Talon Dec 28 '11 at 0:26
    
Fair enough; I think ServerFault might be a better fit, then. –  Su' Dec 28 '11 at 4:09
    
Hmm yeah maybe they'll know better at Server Fault, I didn't even know that section existed. I thought this would be the best fit. –  Talon Dec 28 '11 at 7:58
add comment

4 Answers 4

up vote 1 down vote accepted

Another solution is to override your mail() to use your own function that use an external library like PHPmailer. It is possible with the APD extension.

share|improve this answer
    
Yeah that'll work, that will override everything. –  Talon Dec 31 '11 at 22:31
add comment

On Windows you can force to use SMTP by changing php.ini (but I don't know if you can do authentication):

ini_set ( "SMTP", "smtp-server.example.com" );

On Linux, you need to configure the system-wide local mail agent.

share|improve this answer
    
Would configuring a System Wide Local Mail Agent be something I would contact my webhost about, or can I configure it through WHM, Cpanel, or a server configuration file on my own? –  Talon Dec 29 '11 at 2:01
    
oh and it's a Linux server. –  Talon Dec 29 '11 at 2:01
    
If this is your own server, you can configure your MTA to use a SMTP server, but I don't know about cPanel so I can't answer. –  jcisio Dec 29 '11 at 9:45
    
what is MTA? this is a VPS so it might have access to it. –  Talon Dec 29 '11 at 17:39
    
MTA stands for Mail Transfer Agent. Postfix is a MTA for example. –  The Pixel Developer Dec 29 '11 at 22:45
add comment

You can use phpmailer project to work with email through your codes. This project uses SMTP for its activity. For more information, take a look at http://phpmailer.worxware.com/

share|improve this answer
    
This requires actually using PHPMailer; fine for custom coding but unless I misunderstand, the question is about actually intercepting the use of mail() globally and forcing it through SMTP. –  Su' Dec 28 '11 at 4:07
    
Yeah Su' has it right, there is so many mail notification scripts out there it is really hard to track them all down and actually get them to be SMTP. I know that servers like HostMonster and Bluehost send the PHP through there SMTP server by default. But on a virtual private server that type of setup isn't configured. –  Talon Dec 28 '11 at 7:57
add comment

Check this page, maybe it can be useful :

Send Email from a PHP Script Using SMTP Authentication

share|improve this answer
    
Yeah but I'm trying to apply that type of SMTP authentication globally to all mail() on the server, that will work for new scripts. –  Talon Dec 28 '11 at 7:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.