使用exec();在PHP脚本中从外壳发送电子邮件
问题描述:
我正在尝试制作一个使用exec()
函数的php脚本,以运行发送电子邮件的命令.
I am trying to make a php script that uses the exec()
function to run a command that sends an email.
我正在看这样的东西:
<?php
$sendTo = 'RECEPIENT';
$subject = "SUBJECT";
$message = "MESSAGE";
exec('/bin/mail -s "$sendTo" "$sendTo" < $message');
?>
但是我不确定我在php中声明的变量是否可以在exec()函数中使用.但是,该命令似乎也不正确.
I am not sure however if the variables I have declared in php can be used in the exec() function. The command however also does not seem to be correct.
答
<
是shell重定向,并且需要文件名.
The <
is a shell redirect, and is expecting a filename .
您可以执行类似的操作(尽管我认为还有其他导致邮件运行缓慢的问题)
you can do something like this, (although I think there are other issues causing mail to be slow)
<?php
$mail_command = "/bin/mail -s \"$subject\" $sendTo";
$fd = popen($mail_command, 'w');
fputs($fd,$message);
pclose($fd);
?>