Post 致命错误:类';SendGrid';找不到
我已经编写了一个使用SendGrid的PHP库发送电子邮件的函数。除了我尝试在表单提交事件中使用它之外,它在任何地方都有效 单击“提交”时,我收到一个错误 致命错误:在中找不到类“SendGrid”。。。在线72 提交时的其他一切都正常,帖子被添加到数据库中,但电子邮件没有发送出去 下面是函数Post 致命错误:类';SendGrid';找不到,post,sendgrid,classnotfound,Post,Sendgrid,Classnotfound,我已经编写了一个使用SendGrid的PHP库发送电子邮件的函数。除了我尝试在表单提交事件中使用它之外,它在任何地方都有效 单击“提交”时,我收到一个错误 致命错误:在中找不到类“SendGrid”。。。在线72 提交时的其他一切都正常,帖子被添加到数据库中,但电子邮件没有发送出去 下面是函数 function send_email( $post_id, $templatecode ) { $substitutions = ' "-FNAME-" : "'.$primary_fir
function send_email( $post_id, $templatecode ) {
$substitutions = '
"-FNAME-" : "'.$primary_firstname.'",
"-NAME-" : "'.$primary_name.'",
"-EMAIL-" : "'.$primary_email.'"
';
$to = '
"email": "'.$primary_email.'",
"name": "'.$primary_name.'"
';
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$request_body = json_decode('{
"personalizations": [ {
"substitutions": {'.$substitutions.'},
"to": [ { '.$to.'} ]
} ],
"template_id": "'.$template.'",
"categories": [
"'.$templatecode.'"
],
"from": {
"email": "xxxx",
"name": "xxxxx"
}
}');
$response = $sg->client->mail()->send()->post($request_body);
}
}
这是提交操作
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
$new_post = array(
'post_title' => wp_strip_all_tags( $_POST['title'] ),
'post_content' => $_POST['description'],
'post_status' => 'publish',
'post_type' => 'sessions'
);
$post_id = wp_insert_post($new_post);
send_email( $post_id, 'Submit' );
}