本文介绍了使用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);
?>

这篇关于使用exec();在PHP脚本中从外壳发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:05