为什么我的SendGrid帐户不希望通过Php发送消息?

问题描述

即使我从SendGrid网站键入了正确的代码,我仍然无法通过PHP连接SendGrid,但是它不希望发送消息,并且我的请求也没有出现在SendGrid帐户的“请求”列表中! API密钥正确

        require('sendgrid-PHP/sendgrid-PHP.PHP');
    
        $api_key = "###########";
        $email = new \SendGrid\Mail\Mail();
        
        $email->setFrom("support@codux.me","Codux Inc.");
        $email->setSubject($subject_contacter);
        $email->addTo($email_contacter,$name_contacter);
        $email->addContent("text/plain",$message_contacter);
        
        $sendgrid = new \SendGrid(getenv($api_key));
        
        if($sendgrid->send($email)){
            echo '<div class="alert alert-success">success send</div>';
        } else {
            echo "<div class='alert alert-danger' role='alert'>We apologize! We are unable to receive your request</div>";
        }```

解决方法

我已解决问题,请检查新代码:

Service