2

phpinfo() returns this particular setting which is problematic:

mail.log    /var/log/phpmail.log

The problem is I can't access the phpmail.log file to set the right CHMOD permissions on it, so my error_log is filling up with the following error each time a mail() fires off:

PHP Warning:  mail(/var/log/phpmail.log): failed to open stream: Permission denied

If it's at all possible I'd like to skip logging altogether. Otherwise, define a different log file that I can, you know, actually manipulate.

ps - this is not a duplicate of some other thread. I can't go changing the CHMOD values of above mentioned files, my question is about overriding a setting to skip email logging altogether.

user2777052
  • 157
  • 3
  • 11
  • possible duplicate of [mail: failed to open stream: Permission denied?](http://stackoverflow.com/questions/1906403/mail-failed-to-open-stream-permission-denied) – Protomen Feb 19 '14 at 04:48

4 Answers4

3

I would first try to contact whoever is managing your server, he or she should fix this problem.

If that doesn't work, the mail.log setting is a PHP_INI_PERDIR setting, meaning that:

Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini (since PHP 5.3)

Obviously, you can't access the system's php.ini & httpd.conf, but if a .user.ini is provided to you, or you're allowed to change settings in .htaccess, then that would be a way to solve this.

See:
.user.ini files
Set php.ini Values Using .htaccess

Alternatively, you could consider using Swift Mailer or PHPMailer, which don't need the mail() function. In general, using mail() is discouraged, it's very basic and fairly difficult to use correctly & securely.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
0

You can change the mail.log file path in php.ini setting to a writable location for Apache or any server you are using.

Rohit Choudhary
  • 2,253
  • 1
  • 23
  • 34
-1

I'm a newbie in PHP so I don't know if my solution is really a way to solve this issue or if it works due to a coincidence!

I have the same problem presented here: a call to the PHP function mail() produces a PHP warning. It's all explained in the first message. I also don't possess the permission to edit the mail.log or the directory in which to save it.

Googling, I found a code that call the mail() preceded with a @. I tried to use the code @mail() and it worked!

So this is the working code that I use:

$mail_to = "MyAddress@email.com";
$mail_from = $email; // This e-mail address is taken by an HTML form
$mail_subject = "Test PHP function";
$mail_body = "<p>This is the body message for the test of a PHP function!</p>";

// HTML headers
$mail_in_html = "MIME-Version: 1.0
";
$mail_in_html .= "Content-type: text/html; charset=iso-8859-1
";
$mail_in_html .= "From: <$mail_from>";

// Submission process
if(@mail($mail_to, $mail_subject, $mail_body, $mail_in_html))
{
    print "E-mail sent!";
}
else
{
    print "Error: e-mail not sent.";
}
Wiccio
  • 311
  • 4
  • 14
  • No, don't use @, it's a bad practice - using of Exceptions is better, @ can cause "hidden" errors. You will find it finally find @ before some function after X hours of debugging – Jaroslav Štreit Jun 03 '19 at 23:29
-2

I ended up finding this code and it's good enough:

error_reporting(0);

Inserted right before calling the mail() function. Error_log no longer filling up.

user2777052
  • 157
  • 3
  • 11
  • The problem with this is that you won't get *any* errors any more. such as: *mail() failed to send message*, *you forgot argument 2 for mail()*, *mail() is out of stamps*, etc. I would use this only as a last resort. – Martin Tournoij Feb 19 '14 at 05:12