yii2 联系我们发送邮件报错
为什么会报错,因为国内的邮件服务商要求发送邮件的人和设置的smtp服务器账号要相同,因为联系我们的是用户,也就是发件人是用户,而不是我们配置的邮箱,所有出错。
这里我用了个取巧的办法,发件人改为自己,客户的邮箱信息直接拼接在邮件内容,这样我们收到邮件就能知道谁留下的信息。这样有个好处,自己发邮件给自己,成功概率100%
把控制器改为这样写:
public function actionContact()
{
$model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->body = "访客".$model->email."留言:".$model->body;
$model->email = Yii::$app->params['adminEmail'];
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', '感谢联系我们,我们会尽快联系您!');
} else {
Yii::$app->session->setFlash('error', '邮件发送错误!');
} return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
效果截图:

yii2 联系我们发送邮件报错的更多相关文章
- 发送邮件报错javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed
关于使用javaMail发送邮件报错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multip ...
- 使用 QQ 邮箱发送邮件报错:java.net.SocketTimeoutException: Read timed out. Failed messages: javax.mail.MessagingException: Exception reading response
使用 QQ 邮箱发送邮件报错:java.net.SocketTimeoutException: Read timed out. Failed messages: javax.mail.Messagin ...
- jira发送邮件报错
jira发送邮件的报错 1.安装完jira后,配置发送邮件出错具体报错如下: An error has occurred with sending the test email: com.atlass ...
- jmeter+Jenkins 持续集成中发送邮件报错:MessagingException message: Exception reading response
已经配置好了发送邮件的相关信息,但是执行完脚本出现报错:MessagingException message: Exception reading response 1.查看Jenkins本次构建的控 ...
- 使用SpringBoot + JavaMailSender 发送邮件报错 Mail server connection failed;Could not connect to SMTP host
说明: 出于安全考虑,阿里云默认封禁 TCP 25 端口出方向的访问流量,无法在阿里云上的云服务器通过 TCP 25 端口连接外部地址. [官方提示]:如果您需要使用阿里云上的云服务器对外部发送邮件, ...
- Java发送邮件报错:com.sun.mail.util.LineOutputStream.<init>(Ljava/io/OutputStream;Z)V
在练习使用Java程序发送邮件的代码 运行出现了com.sun.mail.util.LineOutputStream.<init>(Ljava/io/OutputStream;Z)V报错信 ...
- 记一次jenkins发送邮件报错 一直报错 Could not send email as a part of the post-build publishers问题
写在前面 虽然Jenkins是开源.免费的,好处很多,但有些功能上的使用,我个人还是很不喜欢,感觉用起来特别麻烦.繁琐. 为什么? 就拿这个邮件配置来说吧,因重装系统,电脑需要配置很多东西,结果今天就 ...
- php YII2空数组插入报错问题处理 Array to string conversion
问题描述 前端传空数组 [],php接收后处理不当插入数据库时报错Array to string conversion 参数示例 { "id": 0, //ID整型 "t ...
- YII2修改backend模块报错An Error occurred while handling another error: exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in E:\project\demo\vendor\yiisoft
报错内容: 原因:没有修改common/config/bootstrap.php里的别名 修改后:
随机推荐
- Use the SVN command-line tool
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...
- 【英语学习】How do I stop overthinking at night?
2017-04-03 If you were to say to the grown-ups: "I saw a beautiful house made of rosy brick, wi ...
- Eclipse安装Activiti插件(流程设计器)
Eclipse安装Activiti插件(流程设计器) 一.安装步骤: 1,打开Eclipse的 Help -> Install New Software,填上插件地址: Name:Activit ...
- Python基本数据类型之列表
学习Python的列表类型需要了解和掌握什么是列表.列表的可变性.列表的访问.列表的增删改查等操作~ 1.了解列表 list1 = ['abc', 123, {1, 2, 3},[2,3]] Pyth ...
- SVN添加忽略目录
项目:Thinkphp 目录结构: Thinkphp |-- Common |-- Runtime |-- Home 忽略目标: Runtime 文件夹及下面所有文件 首先,需要忽略的目录必须没有加入 ...
- Jquery13 Ajax 进阶
学习要点: 1.加载请求 2.错误处理 3.请求全局事件 4.JSON 和 JSONP 5.jqXHR 对象 一.加载请求 在 Ajax 异步发送请求时,遇到网速较慢的情况,就会出现请求时间较长的问题 ...
- HTTP-java模拟Post请求小栗子
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...
- 【转载】showModalDialog returnValue is undefined in Google Chrome
showModalDialog returnValue is undefined in Google Chrome Posted on August 22, 2012by briancaos For ...
- CentOS(64位)安装apr
安装apr来提高tomcat 的可伸缩性和性能 cd /usr/local/ 1. 下载apr 和 apr-util最新版 wget http://apache.fayea.com/apache-m ...
- pagehelper的使用
知识点:使用pagehelper实现分页功能 参考资料github上:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wiki ...