一、安装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
<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> (责任编辑:最模板) |