opencart安装和使用PHPMailer
2015-08-27 11:36
731 查看
一、安装PHPMailer
1)先给opencart项目安装vqmod
下载最新版本: http://code.google.com/p/vqmod (目前最新版本是vqmod-2.5.1-standard)
把解压出来的文件放到opencart根目录下
执行 http://www.yoursite.com/vqmod/install
你能看到成功信息“VQMOD ALREADY INSTALLED!”. 如果没有,就检查3,4步
2)下载PHPMailerV2.1.zip
把PHPMailerV2.1.zip解压出来的文件夹 upload下的文件:
system/library/phpmailer
vqmod/xml/PHPMailerV2.xml
分别放到opencart项目对应的目录下:
system/library/
vqmod/xml/
二、修复PHPMailerV2.1.zip的PHPMailerV2.xml的2个bug,不知道为啥开发改插件的人没发现
1)PHPMailerV2.xml文件中添加的send()函数,编译生成会导致多出一个'}',去掉126行的'}';
2)xml中的host_name,port,username,password跟opencart项目的变量不对应,应该改成smtp_hostname,smtp_port,smtp_username,smtp_password;
旧xml
修复后的xml:
三、配置opencart后台的mail设置
系统设置->网店设置->编辑
协议选择SMTP,我使用的是smtp.126.com,用户名是你的邮箱 xxx@126.com。注意:你的邮箱必须是开通了smtp权限的才可以
最重要的一点:常规 设置里的E-Mail必须填写成跟 邮件 上面的用户的邮箱一致,因为opencart发邮件所使用的是 常规 设置里的E-Mail
到此完毕!
1)先给opencart项目安装vqmod
下载最新版本: http://code.google.com/p/vqmod (目前最新版本是vqmod-2.5.1-standard)
把解压出来的文件放到opencart根目录下
执行 http://www.yoursite.com/vqmod/install
你能看到成功信息“VQMOD ALREADY INSTALLED!”. 如果没有,就检查3,4步
2)下载PHPMailerV2.1.zip
把PHPMailerV2.1.zip解压出来的文件夹 upload下的文件:
system/library/phpmailer
vqmod/xml/PHPMailerV2.xml
分别放到opencart项目对应的目录下:
system/library/
vqmod/xml/
二、修复PHPMailerV2.1.zip的PHPMailerV2.xml的2个bug,不知道为啥开发改插件的人没发现
1)PHPMailerV2.xml文件中添加的send()函数,编译生成会导致多出一个'}',去掉126行的'}';
2)xml中的host_name,port,username,password跟opencart项目的变量不对应,应该改成smtp_hostname,smtp_port,smtp_username,smtp_password;
旧xml
<modification> <id>PHPMailer</id> <version>2.0</version> <vqmver>1.0.4</vqmver> <author>SpotOnSolutions.net</author> <file name="system/library/mail.php"> <operation> <search position="before"><![CDATA[ class Mail ]]></search> <add><![CDATA[include_once(DIR_SYSTEM . 'library/phpmailer/class.phpmailer.php');]]></add> </operation> <operation> <search position="before"><![CDATA[ protected $subject; ]]></search> <add><![CDATA[ protected $readreceipt;]]></add> </operation> <operation> <search position="before"><![CDATA[ public function setSubject ]]></search> <add><![CDATA[ public function setReadReceipt($readreceipt) { $this->readreceipt = $readreceipt; } ]]></add> </operation> <operation> <search position="before"><![CDATA[public function send() {]]></search> <add><![CDATA[/*]]></add> </operation> <operation> <search position="bottom" offset="2"><![CDATA[ public function send() { ]]></search> <add><![CDATA[*/ public function send() { if (!$this->to) { trigger_error('Error: E-Mail to required!'); exit(); } if (!$this->from) { trigger_error('Error: E-Mail from required!'); exit(); } if (!$this->sender) { trigger_error('Error: E-Mail sender required!'); exit(); } if (!$this->subject) { trigger_error('Error: E-Mail subject required!'); exit(); } if ((!$this->text) && (!$this->html)) { trigger_error('Error: E-Mail message required!'); exit(); } $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; if (is_array($this->to)) { foreach ($this->to as $toTmp){ $mail->AddAddress($toTmp); } } else { $mail->AddAddress($this->to); } if(!empty($this->readreceipt)) { $mail->ConfirmReadingTo = $this->readreceipt; } $mail->Subject = $this->subject; $mail->AddReplyTo($this->from, $this->sender); $mail->SetFrom($this->from, $this->sender); $mail->AddReplyTo($this->from, $this->sender); if (!$this->html) { $mail->Body = $this->text; } else { $mail->MsgHTML($this->html); if ($this->text) { $mail->AltBody = $this->text; } else { $mail->AltBody = 'This is a HTML email and your email client software does not support HTML email!'; } } foreach ($this->attachments as $attachment) { if (file_exists($attachment['file'])) { $mail->AddAttachment($attachment['file']); } } if ($this->protocol == 'smtp') { $mail->IsSMTP(); $mail->Host = $this->hostname; $mail->Port = $this->port; if($this->port == '587'){ $mail->SMTPAuth = true; $mail->SMTPSecure = "tls"; } elseif ($this->port == '465') { $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; } if (!empty($this->username) && !empty($this->password)) { $mail->SMTPAuth = true; $mail->Host = $this->hostname; $mail->Username = $this->username; $mail->Password = $this->password; } } $mail->Send(); } ]]></add> </operation> </file> </modification>
修复后的xml:
<modification> <id>PHPMailer</id> <version>2.0</version> <vqmver>1.0.4</vqmver> <author>SpotOnSolutions.net</author> <file name="system/library/mail.php"> <operation> <search position="before"><![CDATA[ class Mail ]]></search> <add><![CDATA[include_once(DIR_SYSTEM . 'library/phpmailer/class.phpmailer.php');]]></add> </operation> <operation> <search position="before"><![CDATA[ protected $subject; ]]></search> <add><![CDATA[ protected $readreceipt;]]></add> </operation> <operation> <search position="before"><![CDATA[ public function setSubject ]]></search> <add><![CDATA[ public function setReadReceipt($readreceipt) { $this->readreceipt = $readreceipt; } ]]></add> </operation> <operation> <search position="before"><![CDATA[public function send() {]]></search> <add><![CDATA[/*]]></add> </operation> <operation> <search position="bottom" offset="2"><![CDATA[ public function send() { ]]></search> <add><![CDATA[*/ public function send() { if (!$this->to) { trigger_error('Error: E-Mail to required!'); exit(); } if (!$this->from) { trigger_error('Error: E-Mail from required!'); exit(); } if (!$this->sender) { trigger_error('Error: E-Mail sender required!'); exit(); } if (!$this->subject) { trigger_error('Error: E-Mail subject required!'); exit(); } if ((!$this->text) && (!$this->html)) { trigger_error('Error: E-Mail message required!'); exit(); } $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; if (is_array($this->to)) { foreach ($this->to as $toTmp){ $mail->AddAddress($toTmp); } } else { $mail->AddAddress($this->to); } if(!empty($this->readreceipt)) { $mail->ConfirmReadingTo = $this->readreceipt; } $mail->Subject = $this->subject; $mail->AddReplyTo($this->from, $this->sender); $mail->SetFrom($this->from, $this->sender); $mail->AddReplyTo($this->from, $this->sender); if (!$this->html) { $mail->Body = $this->text; } else { $mail->MsgHTML($this->html); if ($this->text) { $mail->AltBody = $this->text; } else { $mail->AltBody = 'This is a HTML email and your email client software does not support HTML email!'; } } foreach ($this->attachments as $attachment) { if (file_exists($attachment['file'])) { $mail->AddAttachment($attachment['file']); } } if ($this->protocol == 'smtp') { $mail->IsSMTP(); $mail->Host = $this->smtp_hostname; $mail->Port = $this->smtp_port; if($this->smtp_port == '587'){ $mail->SMTPAuth = true; $mail->SMTPSecure = "tls"; } elseif ($this->smtp_port == '465') { $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; } if (!empty($this->smtp_username) && !empty($this->smtp_password)) { $mail->SMTPAuth = true; $mail->Host = $this->smtp_hostname; $mail->Username = $this->smtp_username; $mail->Password = $this->smtp_password; } } $mail->Send(); ]]></add> </operation> </file> </modification>
三、配置opencart后台的mail设置
系统设置->网店设置->编辑
协议选择SMTP,我使用的是smtp.126.com,用户名是你的邮箱 xxx@126.com。注意:你的邮箱必须是开通了smtp权限的才可以
最重要的一点:常规 设置里的E-Mail必须填写成跟 邮件 上面的用户的邮箱一致,因为opencart发邮件所使用的是 常规 设置里的E-Mail
到此完毕!
相关文章推荐
- PHPExcel开发者文档[中文版]
- php 获取今日 昨日 本周 上一周 本月 近三个月的起至时间戳
- php页面运行时间记录
- php使用curl模拟提交XML
- FTP服务的高级应用详解
- Yii2 Component基类分析
- PHP 5.4中的traits特性
- PHP使用PHPExcel导出,导入数据总结
- PHP5.3 goto操作符介绍
- 辛星浅析php中coment技术的实现
- 制作yaffs2文件系统简程
- PHP新的垃圾回收机制:Zend GC详解
- Ubuntu配置FTP,SSH,NFS服务
- php trim()函数
- phpcms如何使用推荐位调用自定义字段
- PHP正则表达式及实例
- php实现验证码的识别(初级篇)
- php给图片添加文字水印方法汇总
- php大力力 [026节] php开发状态要随时做好整理工作
- php大力力 [025节] 来不及学习和分类的,大力力认为有价值的一些技术文章合集(大力力二叔公)(2015-08-27)