if(extra_cmd)
extra_cmd = php_escape_shell_arg(extra_cmd);
- if (php_mail(to, subject, message, headers, extra_cmd)) {
+ if (php_mail(to, subject, message, headers, extra_cmd TSRMLS_CC)) {
RETVAL_TRUE;
} else {
RETVAL_FALSE;
/* {{{ php_mail
*/
-PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd)
+PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
{
#ifdef PHP_WIN32
int tsm_err;
#ifdef PHP_WIN32
/* handle old style win smtp sending */
if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
- php_error(E_WARNING, GetSMErrorText(tsm_err));
+ php_error(E_WARNING, "%s() %s", get_active_function_name(TSRMLS_C), GetSMErrorText(tsm_err));
return 0;
}
return 1;
#ifdef PHP_WIN32
sendmail = popen(sendmail_cmd, "wb");
#else
+ /* Since popen() doesn't indicate if the internal fork() doesn't work
+ * (e.g. the shell can't be executed) we explicitely set it to 0 to be
+ * sure we don't catch any older errno value. */
+ errno = 0;
sendmail = popen(sendmail_cmd, "w");
#endif
if (extra_cmd != NULL)
efree (sendmail_cmd);
if (sendmail) {
+#ifndef PHP_WIN32
+ if (EACCES == errno) {
+ php_error(E_WARNING, "%s() permission denied; unable to execute shell to run mail delivery binary",
+ get_active_function_name(TSRMLS_C));
+ return 0;
+ }
+#endif
fprintf(sendmail, "To: %s\n", to);
fprintf(sendmail, "Subject: %s\n", subject);
if (headers != NULL) {
return 1;
}
} else {
- php_error(E_WARNING, "Could not execute mail delivery program");
+ php_error(E_WARNING, "%s() could not execute mail delivery program",
+ get_active_function_name(TSRMLS_C));
return 0;
}
PHP_FUNCTION(mail);
PHP_FUNCTION(ezmlm_hash);
PHP_MINFO_FUNCTION(mail);
-PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd);
+PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC);
#endif