Commit d2758a4a authored by Nickilo's avatar Nickilo

Ajout d'une option pour le port du smtp dans la fonction.

Sortie des logs via zend et non plus via stdout
parent 427982d6
......@@ -7,8 +7,9 @@ $source="your email address";
$reply="reply email address"; // can be empty
$subject="suject";
$content="content";
$smtp="smtp ip or url"; // can be ignored depended on the php.ini configuration
$smtp="smtp ip or url"; // can be ignored depended on the php.ini configuration, see README for more information
$smtp_port="25"; // can be ignored depended on the php.ini configuration, see README for more information
mail_php($login,$password,$destination,$source,$reply,$subject,$content,$smtp);
mail_php($login,$password,$destination,$source,$reply,$subject,$content,$smtp,$smtp_port);
?>
\ No newline at end of file
......@@ -51,7 +51,7 @@ mail_php.enable_sasl=0
mail_php.enable_headers=0
; Smtp server to use, if set to none, smtp serveur has and can be choosen at function call
mail_php.smtp_server="none"
; Smtp port
; Smtp port, if set to none, smtp serveur has and can be choosen at function call
mail_php.smtp_port="587"
; Smtp Ehlo
mail_php.smtp_helo="EHLO PHPMyEmail.sf.net"
......@@ -69,7 +69,7 @@ mail_php.mysql_base="mail_php"
mail_php.footer="0"
; Contenu du footer si active
mail_php.footerContent="Demo footer"
; Debug on (1) or off (0)
; Debug on (1) or off (0) : print smtp session to stdout
mail_php.enable_debug="0"
; Automatically add current date to header (1) (if mail_php.enable_headers=0 )
mail_php.date="0"
......@@ -98,7 +98,7 @@ Where :
USAGE
=========================
String mail_php(String $smtp_login, String $smtp_password, String $to, String $from, String $reply-to, String $subject, String $content [, String $smtp_server] )
String mail_php(String $smtp_login, String $smtp_password, String $to, String $from, String $reply-to, String $subject, String $content [, String $smtp_server [, String $smtp_port] ] )
$smtp_login : Login smtp
$smtp_password : Password smtp
......@@ -108,6 +108,7 @@ $reply-to : Reply mail addresse (can be "" )
$subject : Subject of the email to be sent.
$content : Content to be sent. If mail_php.enable_headers=1, must contain the From: , the To: and the end of the mail headers
$smtp_server (optional) : if mail_php.smtp_server="none", $smtp_server is used
$smtp_port (optional) : if mail_php.smtp_port="none", $smtp_port is used
=========================
TEST
......
......@@ -81,7 +81,7 @@ if [[ $reponse && $reponse = "y" ]];then
echo "" >> $configFile
echo ";[ MAIL PHP ]" >> $configFile
echo "extension=mail_php.so" >> $configFile
echo "mail_php.enable_mysql=1" >> $configFile
echo "mail_php.enable_mysql=0" >> $configFile
echo "mail_php.enable_sasl=1" >> $configFile
echo "mail_php.enable_headers=0" >> $configFile
echo "mail_php.smtp_server=\"none\"" >> $configFile
......@@ -102,7 +102,7 @@ if [[ $reponse && $reponse = "y" ]];then
else
echo "For the module to run, you have to add the following line to your php.ini file :";
echo "extension=mail_php.so";
echo "mail_php.enable_mysql=1";
echo "mail_php.enable_mysql=0";
echo "mail_php.enable_sasl=1";
echo "mail_php.enable_headers=0";
echo "mail_php.smtp_server=\"none\"";
......
......@@ -166,9 +166,11 @@ ZEND_FUNCTION(mail_php)
int subject_len;
char *smtp_server="none";
int smtp_server_len=4;
char *smtp_port="none";
int smtp_port_len=4;
/* Variables recovery */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssssss|s", &login, &login_len, &pass, &pass_len, &to, &to_len, &from, &from_len, &reply, &reply_len, &subject, &subject_len, &content, &content_len, &smtp_server, &smtp_server_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssssss|s|s", &login, &login_len, &pass, &pass_len, &to, &to_len, &from, &from_len, &reply, &reply_len, &subject, &subject_len, &content, &content_len, &smtp_server, &smtp_server_len, &smtp_port, &smtp_port_len) == FAILURE) {
return;
}
......@@ -207,25 +209,30 @@ ZEND_FUNCTION(mail_php)
serverHostEnt = gethostbyname(INI_STR("mail_php.smtp_server"));
}
if (serverHostEnt == NULL) {
printf("probleme gethost\n");
zend_printf("probleme gethost\n");
exit(0);
}
bcopy(serverHostEnt->h_addr,&serverSockAddr.sin_addr,serverHostEnt->h_length);
}
serverSockAddr.sin_port = htons(INI_INT("mail_php.smtp_port")); /* host to network port */
// si le parametre du fichier de conf est none pour le port smtp, on lis l'argument
if (strcmp(INI_STR("mail_php.smtp_port"),"none")==0) {
serverSockAddr.sin_port = htons(atoi(smtp_port)); /* smtp port from parameter */
} else {
serverSockAddr.sin_port = htons(INI_INT("mail_php.smtp_port")); /* smtp port from ini */
}
serverSockAddr.sin_family = AF_INET; /* AF_*** : INET=internet */
/* Socket Creation */
if ( (to_server_socket = socket(AF_INET,SOCK_STREAM,0)) < 0) {
printf("Client socket creation issue\n");
zend_printf("Client socket creation issue\n");
exit(0);
}
/* Connection query */
if(connect(to_server_socket,(struct sockaddr *)&serverSockAddr,sizeof(serverSockAddr))<0) {
printf("Connection query issue\n");
zend_printf("Connection timeout\n");
exit(0);
}
......@@ -245,8 +252,8 @@ void sendsmtp (char *msg) {
writen(to_server_socket,msg,strlen(msg));
readn(to_server_socket,buf,PACKET_SIZE);
if (INI_BOOL("mail_php.enable_debug")) {
printf(" ** Response : ");
printf(buf);
zend_printf(" ** Response : ");
zend_printf(buf);
}
if(regcomp(&re,"(250|354)", REG_EXTENDED) != 0) {
return;
......@@ -452,7 +459,7 @@ int writen(int fd, char *ptr, int n) {
int nl, nw;
nl = n;
if (INI_BOOL("mail_php.enable_debug")) {
printf(ptr);
zend_printf(ptr);
}
while ( nl > 0 ) {
nw = write(fd, ptr, nl);
......@@ -499,7 +506,7 @@ int sql(char *from) {
query= (char *)malloc(100+sizeof(from));
mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,INI_STR("mail_php.mysql_server"),INI_STR("mail_php.mysql_login"),INI_STR("mail_php.mysql_password"),INI_STR("mail_php.mysql_base"),0,NULL,0)) {
printf( "Connection or database issue : %s\n",mysql_error(mysql));
zend_printf( "Connection or database issue : %s\n",mysql_error(mysql));
return 1;
}
strcpy(query,"select fait,limitte from users where mail='");
......@@ -507,17 +514,17 @@ int sql(char *from) {
strcat(query,"' ");
t=mysql_query(mysql,query);
if (t) {
printf("Error making query: %s\n",mysql_error(mysql));
zend_printf("Error making query: %s\n",mysql_error(mysql));
return 1;
}
res=mysql_use_result(mysql);
row=mysql_fetch_row(res);
if (row==NULL) {
printf("You have to be authorized to use this service. Please consult Teria charter. \n");
zend_printf("You have to be authorized to use this service. Please consult Teria charter. \n");
return 1;
}
if (atoi(row[0])>atoi(row[1])) {
printf("Your quota is exceeded\n");
zend_printf("Your quota is exceeded\n");
return 1;
}
mysql_free_result(res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment