Mohammad Aghayari Mohammad Aghayari - 1 year ago 133
PHP Question

Sending SMS in yii2

I'm using two models in one controller. one of them is database model (model) another model is for sending sms (smsModel).

I have problem in smsModel.

I got this error in my result:

Class 'fcadmin\models\SoapClient' not found

How can I fix it?

My controller:

public function actionCreate($id) {

$model = new Requestresult();
$smsModel = new SmsSender();
$request_model = Request::findOne(['id' => $id]);

$model->CodeKargah = $request_model->CodeKargah;
$model->month = $request_model->month;
$model->trackingCode = $request_model->trackingCode;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$smsModel->sendSms('09193452126', 'sdf');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,


public function sendSms($to, $text) {
$options = [
'login' => 'myusername',
'password' => 'mypassword'
$client = new SoapClient('', $options);
$messageId = $client->send($to, $text);
return ($client->deliveryStatus($messageId));

Answer Source

You need to read up about namespaces. If you're in a namespace and don't tell PHP that you want to use the global namespace, it will look for classes of name x in the current namespace.

In your case you need to be using new \SoapClient.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download