把开发平台转移到ubuntu后,本地开发时遇到了一个问题,magento默认的发邮件方式是用匿名smtp,在window下架匿名smtp服务器很简单,可以使用Mail_Direct_Pro这个软件,简单的几步就能架个匿名smtp,但ubuntu下就不一样了,当时考虑了几个方案,最后决定使用修
把开发平台转移到ubuntu后,本地开发时遇到了一个问题,magento默认的发邮件方式是用匿名smtp,在window下架匿名smtp服务器很简单,可以使用Mail_Direct_Pro这个软件,简单的几步就能架个匿名smtp,但ubuntu下就不一样了,当时考虑了几个方案,最后决定使用修改magento源码来使用某些邮件服务商提供的smtp服务,于是在网络上找了方法 http://blog.csdn.net/newjueqi/article/details/7085207 ,但无论是google还是126的smtp服务都不成功。为了测试网上的代码有没有错误,于是写下了以下的测试代码:
$config = array ( 'ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'username' => 'myemailaccount@126.com',
'password' => 'myemailpassword' );
$transport = new Zend_Mail_Transport_Smtp ( 'smtp.126.com', $config );
$mail = new Zend_Mail ();
$mail->setBodyText ( "content" );
$mail->setFrom ( "myemailaccount@126.com", 'Webmaster' );
$mail->addTo ( "h6k65@126.com", '' );
$mail->setSubject ( 'Import attribute logs' );
$mail->send ( $transport );
测试成功,可以发送邮件。
很奇怪,为啥magento下就没法发送邮件。查了一下系统的日志,发现了以下的错误:2011-12-22T06:19:58+00:00 ERR (3): exception 'Zend_Mail_Protocol_Exception' with message 'Mail from must equal authorized user' in /var/www/buymedesign/trunk/lib/Zend/Mail/Protocol/Abstract.php:408哦,原来是smpt使用的email地址和from的email地址不一样
查找 app/code/core/Mage/Core/Model/Email/Template.php中的 send function, 找到如下的代码:
$mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
try {
$mail->send();
$this->_mail = null;
}
catch (Exception $e) {
$this->_mail = null;
Mage::logException($e);
return false;
}
LimeSurvey是一款问卷调查管理系统,具有问卷的设计、修改、发布、回收和统计等多项功能,集成了调查程序开发、调查问卷的发布以及数据收集等功能,使用它,用户不必了解这些功能的编程细节。 LimeSurvey 3.14.2 中文版 更新日志:2018-08-07 -修正问题#13878:向用户组发送电子邮件-显示问题; -修正问题#13902:LimeSurvey尝试在编辑问题时更新响
154
$mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
$mail->setFrom($this->getSenderEmail(), $this->getSenderName()); //
try {
$mail->setFrom("myemailaccount@126.com", 'Webmaster'); //设置新的from信息
$config = array(
'ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'username' => 'myemailaccount@126.com',
'password' => 'myemailpassword');
$transport = new Zend_Mail_Transport_Smtp('smtp.126.com', $config);
$mail->send($transport); //add $transport object as parameter
$this->_mail = null;
}
catch (Exception $e) {
$this->_mail = null;
Mage::logException($e);
return false;
}
return true;
}lib/Zend/Mail.php
public function setFrom($email, $name = null)
{
if (null !== $this->_from) {
/**
* @see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('From Header set twice');
}
$email = $this->_filterEmail($email);
$name = $this->_filterName($name);
$this->_from = $email;
$this->_storeHeader('From', $this->_formatAddress($email, $name), true);
return $this;
}
protected function _storeHeader($headerName, $value, $append = false)
{
if (isset($this->_headers[$headerName])) {
$this->_headers[$headerName][] = $value;
} else {
$this->_headers[$headerName] = array($value);
}
if ($append) {
$this->_headers[$headerName]['append'] = true;
}
} if (isset($this->_headers[$headerName])) {
$this->_headers[$headerName][] = $value;
} else {
$this->_headers[$headerName] = array($value);
} $mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
//$mail->setFrom($this->getSenderEmail(), $this->getSenderName()); //
try {
$mail->setFrom("myemailaccount@126.com", 'Webmaster'); //设置新的from信息
$config = array(
'ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'username' => 'myemailaccount@126.com',
'password' => 'myemailpassword');
$transport = new Zend_Mail_Transport_Smtp('smtp.126.com', $config);
$mail->send($transport); //add $transport object as parameter
$this->_mail = null;
}
catch (Exception $e) {
$this->_mail = null;
Mage::logException($e);
return false;
}
return true;
}【文章标题】调试php没法使用smtp发送邮件的问题
【文章作者】曾健生
【作者邮箱】zengjiansheng1@126.com
【作者QQ】190678908
【作者博客】blog.csdn.net/newjueqi
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号