1999-04-17 00:37:12 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 13:13:16 +00:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 06:11:02 +00:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 15:34:45 +00:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 15:34:45 +00:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-06-06 13:06:12 +00:00
|
|
|
| Authors: Rasmus Lerdorf <rasmus@php.net> |
|
1999-04-17 00:37:12 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "php.h"
|
2000-04-05 21:43:03 +00:00
|
|
|
#include "ext/standard/info.h"
|
2000-02-11 15:59:30 +00:00
|
|
|
#if !defined(PHP_WIN32)
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "build-defs.h"
|
2001-01-21 17:29:15 +00:00
|
|
|
#if HAVE_SYSEXITS_H
|
2000-08-03 19:26:19 +00:00
|
|
|
#include <sysexits.h>
|
1999-04-17 00:37:12 +00:00
|
|
|
#endif
|
2001-01-21 17:29:15 +00:00
|
|
|
#if HAVE_SYS_SYSEXITS_H
|
|
|
|
#include <sys/sysexits.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
1999-12-04 19:19:57 +00:00
|
|
|
#include "php_mail.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "php_ini.h"
|
2001-07-05 08:47:37 +00:00
|
|
|
#include "safe_mode.h"
|
2001-07-08 19:09:59 +00:00
|
|
|
#include "exec.h"
|
1999-04-17 00:37:12 +00:00
|
|
|
|
|
|
|
#if HAVE_SENDMAIL
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 00:37:12 +00:00
|
|
|
#include "win32/sendmail.h"
|
|
|
|
#endif
|
|
|
|
|
2000-06-29 14:07:10 +00:00
|
|
|
/* {{{ proto int ezmlm_hash(string addr)
|
|
|
|
Calculate EZMLM list hash value. */
|
|
|
|
PHP_FUNCTION(ezmlm_hash)
|
|
|
|
{
|
|
|
|
pval **pstr = NULL;
|
|
|
|
char *str=NULL;
|
|
|
|
unsigned long h = 5381L;
|
|
|
|
int j, l;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pstr) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(pstr);
|
|
|
|
if ((*pstr)->value.str.val) {
|
|
|
|
str = (*pstr)->value.str.val;
|
|
|
|
} else {
|
|
|
|
php_error(E_WARNING, "Must give string parameter to ezmlm_hash()");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = strlen(str);
|
|
|
|
for (j=0; j<l; j++) {
|
|
|
|
h = (h + (h<<5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
h = (h%53);
|
|
|
|
|
|
|
|
RETURN_LONG((int) h);
|
|
|
|
}
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
2000-06-29 14:07:10 +00:00
|
|
|
|
2001-02-05 21:30:29 +00:00
|
|
|
/* {{{ proto int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
|
1999-04-17 00:37:12 +00:00
|
|
|
Send an email message */
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(mail)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-02-05 21:30:29 +00:00
|
|
|
pval **argv[5];
|
|
|
|
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *extra_cmd=NULL;
|
1999-04-17 00:37:12 +00:00
|
|
|
int argc;
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
argc = ZEND_NUM_ARGS();
|
2001-02-05 21:30:29 +00:00
|
|
|
if (argc < 3 || argc > 5 || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
|
1999-04-17 00:37:12 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
/* To: */
|
1999-09-25 12:09:50 +00:00
|
|
|
convert_to_string_ex(argv[0]);
|
|
|
|
if ((*argv[0])->value.str.val) {
|
|
|
|
to = (*argv[0])->value.str.val;
|
1999-04-17 00:37:12 +00:00
|
|
|
} else {
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_WARNING, "No to field in mail command");
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subject: */
|
1999-09-25 12:09:50 +00:00
|
|
|
convert_to_string_ex(argv[1]);
|
|
|
|
if ((*argv[1])->value.str.val) {
|
2001-07-05 08:47:37 +00:00
|
|
|
subject = Z_STRVAL_PP(argv[1]);
|
1999-04-17 00:37:12 +00:00
|
|
|
} else {
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_WARNING, "No subject field in mail command");
|
1999-04-17 00:37:12 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* message body */
|
1999-09-25 12:09:50 +00:00
|
|
|
convert_to_string_ex(argv[2]);
|
|
|
|
if ((*argv[2])->value.str.val) {
|
2001-07-05 08:47:37 +00:00
|
|
|
message = Z_STRVAL_PP(argv[2]);
|
1999-04-17 00:37:12 +00:00
|
|
|
} else {
|
|
|
|
/* this is not really an error, so it is allowed. */
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_WARNING, "No message string in mail command");
|
1999-04-17 00:37:12 +00:00
|
|
|
message = NULL;
|
|
|
|
}
|
|
|
|
|
2001-02-05 21:30:29 +00:00
|
|
|
if (argc >= 4) { /* other headers */
|
1999-09-25 12:09:50 +00:00
|
|
|
convert_to_string_ex(argv[3]);
|
2001-07-05 08:47:37 +00:00
|
|
|
headers = Z_STRVAL_PP(argv[3]);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
|
2001-02-05 21:30:29 +00:00
|
|
|
if (argc == 5) { /* extra options that get passed to the mailer */
|
|
|
|
convert_to_string_ex(argv[4]);
|
2001-07-05 08:47:37 +00:00
|
|
|
extra_cmd = php_escape_shell_arg(Z_STRVAL_PP(argv[4]));
|
2001-02-05 21:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (php_mail(to, subject, message, headers, extra_cmd)) {
|
2001-07-05 08:47:37 +00:00
|
|
|
RETVAL_TRUE;
|
1999-04-17 00:37:12 +00:00
|
|
|
} else {
|
2001-07-05 08:47:37 +00:00
|
|
|
RETVAL_FALSE;
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2001-07-08 22:30:11 +00:00
|
|
|
if (extra_cmd) efree (extra_cmd);
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ php_mail
|
|
|
|
*/
|
2001-06-11 15:18:44 +00:00
|
|
|
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 00:37:12 +00:00
|
|
|
int tsm_err;
|
2001-07-08 22:30:11 +00:00
|
|
|
#endif
|
1999-04-17 00:37:12 +00:00
|
|
|
FILE *sendmail;
|
|
|
|
int ret;
|
|
|
|
char *sendmail_path = INI_STR("sendmail_path");
|
2001-02-05 21:30:29 +00:00
|
|
|
char *sendmail_cmd = NULL;
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2001-07-08 22:30:11 +00:00
|
|
|
if (!sendmail_path) {
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
2001-07-08 22:30:11 +00:00
|
|
|
/* 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));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
1999-04-17 00:37:12 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
2001-07-08 22:30:11 +00:00
|
|
|
#endif
|
1999-04-17 00:37:12 +00:00
|
|
|
}
|
2001-02-05 21:30:29 +00:00
|
|
|
if (extra_cmd != NULL) {
|
|
|
|
sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2);
|
|
|
|
strcpy (sendmail_cmd, sendmail_path);
|
|
|
|
strcat (sendmail_cmd, " ");
|
|
|
|
strcat (sendmail_cmd, extra_cmd);
|
|
|
|
} else {
|
|
|
|
sendmail_cmd = sendmail_path;
|
|
|
|
}
|
|
|
|
|
2001-07-08 22:30:11 +00:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
sendmail = popen(sendmail_cmd, "wb");
|
|
|
|
#else
|
2001-02-05 21:30:29 +00:00
|
|
|
sendmail = popen(sendmail_cmd, "w");
|
2001-07-08 22:30:11 +00:00
|
|
|
#endif
|
2001-02-05 21:30:29 +00:00
|
|
|
if (extra_cmd != NULL)
|
|
|
|
efree (sendmail_cmd);
|
1999-04-17 00:37:12 +00:00
|
|
|
|
|
|
|
if (sendmail) {
|
|
|
|
fprintf(sendmail, "To: %s\n", to);
|
|
|
|
fprintf(sendmail, "Subject: %s\n", subject);
|
|
|
|
if (headers != NULL) {
|
|
|
|
fprintf(sendmail, "%s\n", headers);
|
|
|
|
}
|
|
|
|
fprintf(sendmail, "\n%s\n", message);
|
|
|
|
ret = pclose(sendmail);
|
2001-07-08 22:30:11 +00:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
if (ret == -1)
|
|
|
|
#else
|
2001-03-21 15:15:31 +00:00
|
|
|
#if defined(EX_TEMPFAIL)
|
2001-07-08 22:30:11 +00:00
|
|
|
if ((ret != EX_OK)&&(ret != EX_TEMPFAIL))
|
2001-03-21 15:15:31 +00:00
|
|
|
#else
|
2001-07-08 22:30:11 +00:00
|
|
|
if (ret != EX_OK)
|
|
|
|
#endif
|
2001-03-21 15:15:31 +00:00
|
|
|
#endif
|
2001-07-08 22:30:11 +00:00
|
|
|
{
|
1999-04-17 00:37:12 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_WARNING, "Could not execute mail delivery program");
|
1999-04-17 00:37:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
1999-04-17 00:37:12 +00:00
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINFO_FUNCTION(mail)
|
1999-04-17 00:37:12 +00:00
|
|
|
{
|
2001-07-08 22:30:11 +00:00
|
|
|
char *sendmail_path = INI_STR("sendmail_path");
|
2001-07-30 06:18:13 +00:00
|
|
|
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
if (!sendmail_path) {
|
|
|
|
php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled");
|
|
|
|
} else {
|
|
|
|
php_info_print_table_row(2, "Path to sendmail", sendmail_path);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
php_info_print_table_row(2, "Path to sendmail", sendmail_path);
|
1999-04-17 00:37:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
1999-04-17 00:37:12 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
1999-05-16 11:19:26 +00:00
|
|
|
PHP_FUNCTION(mail) {}
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINFO_FUNCTION(mail) {}
|
1999-04-17 00:37:12 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
2001-06-05 13:12:10 +00:00
|
|
|
* c-basic-offset: 4
|
1999-04-17 00:37:12 +00:00
|
|
|
* End:
|
2001-06-06 13:06:12 +00:00
|
|
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4 tw=78
|
1999-04-17 00:37:12 +00:00
|
|
|
*/
|