Home > Backend Development > PHP Tutorial > PHP调用.bat文件的有关问题

PHP调用.bat文件的有关问题

PHP中文网
Release: 2023-02-28 14:32:01
Original
1556 people have browsed it

  PHP调用.bat文件的问题 急求高手指教
我用perl写了一个bat文件,功能就是简单的邮件发送。现在我想在PHP里面调用这个bat,我试着用system和exec调用:

system('cmd\C C:\Documents and Settings\nshi\Bureau\dev redmine-sugar\phpmail.bat',$result);
//exec('cmd\C C:\Documents and Settings\nshi\Bureau\dev redmine-sugar\phpmail.bat',$result);
echo "result : ".$result;
Copy after login

结果是用system命令得到的输出结果是 result : 1
而exec输出结果是 result : Array
而且2次的邮件都没有发送成功。

我bat文件的代码就一行

perl.exe phpmail.pl
Copy after login

其中phpmail.pl的代码:

use Net::SMTP;
use MIME::Lite;               
                my $Message = MIME::Lite->new(
                From =>"123\@sina.com",   
                To =>"456\@sina.com",
                Subject =>"SUJET",
                Type    =>'multipart/related'
                );
                 
                $Message->attach
                (
                Type =>'text/html',
                Data =>"MESSAGE 
!!!!
"
                );
                 
                MIME::Lite->send('smtp', "smtp.sina.com", Timeout=>90,Port =>"25");  
                   $Message->send();
Copy after login

在windows命令行直接运行bat文件的话,邮件成功发送,但是用php调用就发生了上述的情况,邮件都没有被成功发送。
请问有没有前辈能帮我看看到底是哪出了问题?
PS:或者哪位高手能讲讲如果用PHP发送邮件?用smtp的
先谢谢了

------解决方案--------------------

  • PHP code

<?php
system(&#39;cmd /c c:\test.bat&#39;);

///////

system(&#39;perl.exe d:\test.pl&#39;); //perl.exe必须在系统环境变量中
?>
Copy after login

 以上就是PHP调用.bat文件的有关问题  的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template