php里push的用法,在php中使用array_push方法

addRecipients使用push_array,但它不起作用。我在这里做错了什么?

在class.emailer.php中

class Emailer

{

public $sender;

public $recipients;

public $subject;

public $body;

function __construct($sender)

{

$this->sender = $sender;

$this->recipients = array();

}

public function addRecipients($recipient)

{

array_push($this->recipients, $recipient);

}

public function setSubject($subject)

{

$this->subject = $subject;

}

public function setBody($body)

{

$this->body = $body;

}

public function sendEmail()

{

echo "From sendEmail, send email initiated
";

echo "Body: ".$this->body."
";

echo "Subject: ".$this->subject."
";

print_r ($this->sender);

print_r ($this->recipients);

echo "
";

foreach ($this->recipients as $recipient)

{

echo "6
";

//$result = mail($recipient, $this->subject, $this->body,"From: {$this->sender}\r\n");

echo "7
";

if ($result) echo "Mail successfully sent to {$recipient}
";

}

}}

并在class.extendedemailer.php

include_once("class.emailer.php");

class ExtendedEmailer extends emailer

{

function __construct(){

//overwriting __contruct here

}

public function setSender($sender)

{

$this->sender = $sender;

}

}并在sendemail.php

include_once("class.extendedemailer.php");

echo "start 1
";

$xemailer = new ExtendedEmailer();

echo "1. adding sender:
";

$xemailer->setSender("sender@mywebsite.com");

print_r ($xemailer->sender);

echo "
2. adding recipients:
";

$xemailer->addRecipients("recipientemail@gmail.com");

var_dump ($xemailer->recipients);

echo "
3. adding subject:
";

$xemailer->setSubject("Just a Test
");

print_r ($xemailer->subject);

echo "4. adding body
";

$xemailer->setBody("Hi, How are you?
");

print_r ($xemailer->body);

echo "5. sending email
";

$xemailer->sendEmail();收件人的输出是NULL。

start 1

1. adding sender:

sender@mywebsite.com

2. adding recipients:

NULL

3. adding subject:

Just a Test

4. adding body

Hi, How are you?

5. sending email

From sendEmail, send email initiated

Body: Hi, How are you?

Subject: Just a Test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值