メールブロックを初期化するコードブロックを使用したいが、コードを関数に移動するたびにスクリプトが実行を停止してから電子メールを送信する。私はそれが正常に動作します。この機能を使用してWebページをロードし、適切な電子メール送信する場合:スクリプトを停止させる関数にコードを移動する
function SendAdminIntimationEmail(&$formvars)
{
if(empty($this->admin_email))
{
return false;
}
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
//Tell PHPMailer to use SMTP
$mailer->isSMTP();
//Set the hostname of the mail server
$mailer->Host = "test.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mailer->Port = 25;
//Whether to use SMTP authentication
$mailer->SMTPAuth = false;
//Username to use for SMTP authentication
$mailer->Username = "[email protected]";
//Password to use for SMTP authentication
$mailer->Password = "pword";
//Set who the message is to be sent from
$mailer->setFrom('[email protected]', 'test');
//Set an alternative reply-to address
$mailer->addReplyTo('[email protected]', 'First Last');
$mailer->AddAddress($this->admin_email);
$mailer->Subject = "New registration: ".$formvars['name'];
$mailer->From = $this->GetFromAddress();
$mailer->Body ="A new user registered at ".$this->sitename."\r\n".
"Name: ".$formvars['name']."\r\n".
"Email address: ".$formvars['email']."\r\n".
"UserName: ".$formvars['username'];
if(!$mailer->Send())
{
return false;
}
return true;
}
しかし、私は別の関数にコードのブロックを移動し、その機能を渡すしようとすると、$メーラーがWebページオブジェクトを空白のページが読み込まれ、電子メールは送信されません。非稼働コード:
function SendAdminIntimationEmail(&$formvars)
{
if(empty($this->admin_email))
{
return false;
}
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
InitSMTPMailer($mailer);
$mailer->AddAddress($this->admin_email);
$mailer->Subject = "New registration: ".$formvars['name'];
$mailer->From = $this->GetFromAddress();
$mailer->Body ="A new user registered at ".$this->sitename."\r\n".
"Name: ".$formvars['name']."\r\n".
"Email address: ".$formvars['email']."\r\n".
"UserName: ".$formvars['username'];
if(!$mailer->Send())
{
return false;
}
return true;
}
function InitSMTPMailer($mailer)
{
//Tell PHPMailer to use SMTP
$mailer->isSMTP();
//Set the hostname of the mail server
$mailer->Host = "test.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mailer->Port = 25;
//Whether to use SMTP authentication
$mailer->SMTPAuth = false;
//Username to use for SMTP authentication
$mailer->Username = "[email protected]";
//Password to use for SMTP authentication
$mailer->Password = "pword";
//Set who the message is to be sent from
$mailer->setFrom('[email protected]', 'test');
//Set an alternative reply-to address
$mailer->addReplyTo('[email protected]', 'test');
return $mailer;
}
それは便利だ場合、この関数は常にこの関数によって呼び出されます。
function RegisterUser()
{
if(!isset($_POST['submitted']))
{
return false;
}
$formvars = array();
if(!$this->ValidateRegistrationSubmission())
{
return false;
}
$this->CollectRegistrationSubmission($formvars);
if(!$this->SaveToDatabase($formvars))
{
return false;
}
if(!$this->SendUserConfirmationEmail($formvars))
{
return false;
}
$this->SendAdminIntimationEmail($formvars);
return true;
}
スクリプトが正常に動作しない作っている機能を追加した後、そののregisterUser(表示されます)は$ this-> SendAdminIntimationEmail($ formvars)で失敗します。なぜなら、SendUserConfirmationEmail($ formvars)関数は依然として電子メールを送信するからです。
これはシンプルなのですが、申し訳ありませんが、参考にしたり値を渡したりすることで何か間違ったことをしていますか?
空白のページ= PHPがクラッシュして、あなたは無効になってすべてのデバッグオプションがあります。
これを試してみてください。それらをオンにして、もう一度やり直してください。最初はdevel/debugシステムではOFFにしてはいけません。あなたの耳にあなたの指を詰め込み、 "ララルララはあなたの声を聞くことができません"というコードに相当します。 –
これらの機能はクラスの一部ですか? '$ this'はクラス内での使用のためのものです。 –
'InitSMTPMailer'はメーラーを返しますが、あなたはそれを割り当てておらず、参照によって渡していません。 – aynber