我正在尝试使用SMTP从我的服务器发送邮件。一切顺利,但不发送邮件。
我不怎么样,但它不会取<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div>
<div class="same">Text</div>
<div class="same">Text</div>
<div class="same">Text</div>
<div class="not-same">Stop here</div>
<div class="same">Text</div>
<div class="same">Text</div>
</div>
值。
这是我的功能代码:
$to
这是我的观看代码:
public function sendEmail($to='',$from='',$subject='',$body='' , $record_id='')
{
$from1=Yii::app()->functions->getOptionAdmin('global_admin_sender_email');
if (!empty($from1)){
$from=$from1;
}
$email_dsiabled_auto_break=getOptionA('email_dsiabled_auto_break');
if($email_dsiabled_auto_break!=1){
$body=nl2br($body);
}
$send_status=false; $send_msg='';
$email_provider=Yii::app()->functions->getOptionAdmin('email_provider');
//dump($email_provider);
switch ($email_provider) {
case "smtp":
$smtp_host=Yii::app()->functions->getOptionAdmin('smtp_host');
$smtp_port=Yii::app()->functions->getOptionAdmin('smtp_port');
$smtp_username=Yii::app()->functions->getOptionAdmin('smtp_username');
$smtp_password=Yii::app()->functions->getOptionAdmin('smtp_password');
$mail=Yii::app()->Smtpmail;
Yii::app()->Smtpmail->Host=$smtp_host;
Yii::app()->Smtpmail->Username=$smtp_username;
Yii::app()->Smtpmail->Password=$smtp_password;
Yii::app()->Smtpmail->Port=$smtp_port;
$mail->SetFrom($from, '');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($to, "");
if($mail->Send()) {
$mail->ClearAddresses();
$send_msg=t("error occurred");
} else {
$mail->ClearAddresses();
$send_status=true;
$send_msg="sent";
}
break;
我提到了一些问题: How to send Mail Using SMTP?
我没有得到错误。欢迎任何形式的帮助。
答案 0 :(得分:0)
成功完成$mail->Send()
时会触发错误,否则会设置$send_status=true;
。
尝试将其还原
if($mail->Send()) {
$mail->ClearAddresses();
$send_status=true;
$send_msg="sent";
} else {
$mail->ClearAddresses();
$send_msg=t("error occurred");
}
请参阅官方文档:http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html