ارسال ایمیل با استفاده از تابع swiftmailer در Yii1

ارسال ایمیل با استفاده از تابع swiftmailer در Yii1

یکی از روش های ارسال ایمیل در فریم ورک Yii نسخه ی ۱ استفاده از swiftmailer می باشد

۱-برای این کار ابتدا آن را از لینک زیر دانلود کنید
دانلود swiftmailer

۲- آن را extract کرده و در فولدر extensions قرار دهید:

۳- قرار دادن swiftmailer در تنظیمات
فولدر config قایل main.php

'swiftMailer' => array(
'class' => 'ext.swiftMailer.SwiftMailer',
),

یا می توانید آن را به صورت زیر هر جایی که خواستید ایمیل ارسال کنید صدا بزنید

Yii::import('ext.swiftMailer.SwiftMailer');

۴- نحوه ارسال و استفاده

$plainTextContent = "This is my Plain Text Content for those with cheap emailclients ;-)\nThis is my second row of text";

// Get mailer
$SM = Yii::app()->swiftMailer;

// Get config
$mailHost = 'mail.example.com';
$mailPort = 25; // Optional

// New transport
$Transport = $SM->smtpTransport($mailHost, $mailPort);

// Mailer
$Mailer = $SM->mailer($Transport);

// New message
$Message = $SM
->newMessage('My subject')
->setFrom(array('from@example.com' => 'Example Name'))
->setTo(array('recipient@example.com' => 'Recipient Name'))
->addPart($content, 'text/html')
->setBody($plainTextContent);

// Send mail
$result = $Mailer->send($Message);

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *