值更改时使用php发送电子邮件

时间:2019-03-14 15:31:49

标签: php email

我想通过Php发送电子邮件,以通知状态更改。这是代码。

public function statut( $id ) {

    $info = get_post_meta( $id, '_ecole_statut', true );

    $statut = array(
        'transport'         => 'Transport normal',
        'transport_cl'      => 'success',
        'ecole'                 => 'École ouverte',
        'ecole_cl'          => 'success',
        'commentaire'   => ''
    );

    if( $info && current_time( 'timestamp' ) <= $info['date'] ){
        switch ($info['transport']){
            case "non":
                $statut['transport'] = "Transport annulé";
                $statut['transport_cl'] = 'danger';
            break;
            case "autre":
                $statut['transport'] = "Transport perturbé";
                $statut['transport_cl'] = 'warning';
            break;
            default:
                $statut['transport']  = "Transport normal";
                $statut['transport_cl'] = 'success';
            break;
        }
        switch ($info['ecole']){
            case "non":
                $statut['ecole'] = "École fermée";
                $statut['ecole_cl'] = 'danger';
            break;
            default:
                $statut['ecole'] = "École ouverte";
                $statut['ecole_cl'] = 'success';
            break;
        }

        $statut['commentaire'] = !empty( $info['commentaire'] ) ? '<small>' . $info['commentaire'] . '</small>' : '';
    }

    return $statut;
}

这是我尝试的那行,但是它正在为所有学校列表发送电子邮件,而不是仅发送给那些更改的学校,而我在收件箱中以10封电子邮件结尾。我想用“运输年鉴”,“运输扰动”和“费科尔费米”来显示学校的名称和学校的状态。

if ($tatut ['transport'] = "Transport annulé")
{
    mail('aport-lis@cscmonavenir.ca',
         'Nouvelle alerte intemperies',
          "".$abbr." Transport " .$statut['transport'] .
          " Ecole ".$statut['ecole']."");
}

2 个答案:

答案 0 :(得分:0)

if ($tatut ['transport'] = "Transport annulé")需要阅读if ($tatut ['transport'] == "Transport annulé")

使用单=时,如果在if语句中将值设置为“ Transportannulé”,则需要使用双==进行比较。

答案 1 :(得分:0)

这行看起来有问题

if ($tatut ['transport'] = "Transport annulé")

首先,它看起来像是一个错字,而不是$tatut,您想要的是$statut。但是除此之外,比较使用==(或===)。使用单个=意味着分配,并且您的条件始终为true