我们设置好opencart的smtp后,在网站留言处出现错误提示:“Error: MAIL FROM not accepted from server!”
解决有两种方法:
一,修改opencart的邮件发送mail函数,可能主机不支持mail函数。修改麻烦,放弃!
二:发件人是自己,修改opencart本身的php文件,用户填写的邮箱通过邮件传送代码即可。
具体修改文件“contact.php”即可.
打开这个文件,找到如下代码:
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
//www.zuimoban.com
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
$mail->send();
$this->redirect($this->url->link('information/contact/success'));
}
这里POST参数:email、name 和 enquiry ,对应的是用户填写的邮件地址、名字和邮件内容。
//收件人
$mail->setTo($this->config->get('config_email'));
//发件人
$mail->setFrom($this->request->post['email']);
修改为:
//收件人
$mail->setTo($this->config->get('config_email'));
//发件人
$mail->setFrom($this->config->get('config_email'));
//收件人名称修改
$mail->setSender($this->request->post['name']);
//修改为:
$mail->setSender($this->request->post['name'].'<'.$this->request->post['email'].'>');
这里定义发件人邮箱地址。
会出现报错:“Error: RCPT TO not accepted from server!”,
解决办法:
//收件人
$mail->setTo($this->config->get('config_email'));
//改为自己定义的:
$mail->setTo('你的邮箱地址');
问题解决. |