不确定我的问题是否正确,但是我想达到的目标是将cc添加到另一个类的方法内部的wp_mail中。
class Hello_World {
function __construct () {
....
}
function dispatch_email() {
$to = 'To: email@email.com';
$subject = 'Subject';
$body = 'Content';
$header[] = 'From: from@email.com';
$header[] = 'Content-Type: text/html; charset=UTF-8';
wp_mail( $to, $subject, $body, $header );
}
}
如何从我的新班级的wp_mail中添加新标题?我在下面尝试了但没有用..
$Hi_World = new Hello_World;
$Hi_World->dispatch_email()->header[] = 'Cc: new@email.com';
答案 0 :(得分:0)
我正在打电话,所以无法测试,但是,如果向构造函数添加参数,则可以通过以下方式实现目标:
class Hello_World {
function __construct ($headers) {
this->headers = $headers;
....
}
function dispatch_email() {
$to = 'To: email@email.com';
$subject = 'Subject';
$body = 'Content';
$header[] = 'From: from@email.com';
$header[] = 'Content-Type: text/html; charset=UTF-8';
$fullHeaders = array_merge($header, this->headers);
wp_mail( $to, $subject, $body, $fullHeaders );
}
}
$Hi_World = new Hello_World(['Cc: new@email.com']);
$Hi_World->dispatch_email();