命令的形式
#!/usr/bin/php -q
<?
$email="[email protected]";
send_email($email);
function send_email($email){
$header="Content-type: text/html; charset=gb2312\r\n";
$header .= 'From: <[email protected]>' . "\r\n";
$from="[email protected]";
$subject="给您发送信息";
$message="<html><body>";
$message .= "<br><br>你好<br><br>";
$message .="</body></html>";
mail($email,$subject,$message,$header) or die("Sorry,Failure");
}?>这样是可以发送命令的
使用
1.php
<?
$email="[email protected]";
send_email($email);
function send_email($email){
$header="Content-type: text/html; charset=gb2312\r\n";
$header .= 'From: <[email protected]>' . "\r\n";
$from="[email protected]";
$subject="给您发送信息";
$message="<html><body>";
$message .= "<br><br>你好<br><br>";
$message .="</body></html>";
mail($email,$subject,$message,$header) or die("Sorry,Failure");
}?>这样的形式,通过浏览器打开则不能发送邮件。不知道为什么?
#!/usr/bin/php -q
<?
$email="[email protected]";
send_email($email);
function send_email($email){
$header="Content-type: text/html; charset=gb2312\r\n";
$header .= 'From: <[email protected]>' . "\r\n";
$from="[email protected]";
$subject="给您发送信息";
$message="<html><body>";
$message .= "<br><br>你好<br><br>";
$message .="</body></html>";
mail($email,$subject,$message,$header) or die("Sorry,Failure");
}?>这样是可以发送命令的
使用
1.php
<?
$email="[email protected]";
send_email($email);
function send_email($email){
$header="Content-type: text/html; charset=gb2312\r\n";
$header .= 'From: <[email protected]>' . "\r\n";
$from="[email protected]";
$subject="给您发送信息";
$message="<html><body>";
$message .= "<br><br>你好<br><br>";
$message .="</body></html>";
mail($email,$subject,$message,$header) or die("Sorry,Failure");
}?>这样的形式,通过浏览器打开则不能发送邮件。不知道为什么?
猜的
但也不对啊。
用命令的形式是可以发送邮件的。
网页的形式则不行。
我使用的是sendmail
就是网页的形式运行php,它的使用的访问用户是什么?apache?还是此php的拥有者?就那我上面的程序来说。
$ls -al
..............
-rw-rw-r-- 1 test test 401 Aug 6 08:42 mail_test_html.php
-rwxr-xr-x 1 test test 7408 Jun 14 07:01 mail_test.php
.................这2个程序中发送邮件内容都是一样的 。只是mail_test.php 以命令的形式发送邮件。mail_test_html.php网页打开发送邮件。
为什么 ./mail_test.php 能成功
而 http://www.XXX.com/mail_test_html.php 就不能发送成功呢?
关掉selinux 就可以了:)vi /etc/selinux/config
找到
SELINUX=enforcing
改为
SELINUX=disabled然后重启系统,问题就解决了.
它们不是一个域的.
不过简单的关掉,只是个偷懒的办法.
selinux能够让linux的安全提高一个级别.好像是从c到b+