php - 无法使用 cron 发送电子邮件?
问题描述
创建了 PHP 脚本来发送邮件并将 cron 作业设置为每 5 分钟发送一次。
但是邮件没有收到。请检查下面的脚本并帮助我解决。
<?php
$to = "ravxxxx@gmail.com";
$subject = "HTML email";
$message = "Error Message returned by"
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\b";
$headers .= 'From: anxxxxx@domain.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
cron 选项卡:crontab -l
5 * * * * /path/mail.php
解决方案
您是否尝试过在 cron 中指定 php 路径?
示例(查找您的 php 二进制文件的路径,我正在使用示例):
*/5 * * * * /usr/bin/php /path/mail.php
推荐阅读
- linux - 日期和条件 bash 命令的奇怪但非常简单的问题
- php - 如何使用 php 和 mysqli 按月显示计数事件
- javascript - 通过 ID 访问数组中的多个键
- php - 检查所有者和中间件中资源的存在以避免在控制器中重复自身?
- javascript - 如何模拟 sns?
- asp.net - 我可以将我的 .net 4.8 webforms webapp 升级到 .net 5.0 吗?
- sql - 确定特定客户在特定月份第一次访问商店
- vb.net - vb.net 线程和加载面板
- python - 如何返回一个单词的字母,而不是只返回一个字母?Python
- android - 我的 android 应用程序如何找到从 PC 下载的文件?