首页 > 解决方案 > 无法使用 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

标签: phpcron

解决方案


您是否尝试过在 cron 中指定 php 路径?

示例(查找您的 php 二进制文件的路径,我正在使用示例):

*/5 * * * * /usr/bin/php /path/mail.php


推荐阅读