电子邮件联系表未发送并给出错误 Zend Framework 2
Email contact form not sending and gives an error Zend Framework 2
我继承了一个使用 zend framework 2 构建的客户网站。我已经弄清楚如何将它移动到我的主机上,这很好,但仍然存在一个问题,那就是电子邮件联系表。通过联系表发送电子邮件时,出现以下错误。我怀疑它是一个配置区域,但在我想知道是否有人可以指出我正确的方向来修复这个错误之前我没有使用过这个系统。
干杯
发生错误。异常:\n #0 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(149): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://auth.smtp...') #1 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php( 340): Zend\Mail\Protocol\Smtp->connect() #2 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(326): Zend\Mail\Transport\Smtp->connect() #3 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(337): Zend\Mail\Transport\Smtp->lazyLoadConnection() #4 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(204): Zend\Mail\Transport\Smtp->connect() #5 /homepages/43/d387176596/htdocs/zAJSL/vendor/acelaya/zf2-acmailer/src/Service/MailService.php(88): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message)) #6 /homepages/43/d387176596/htdocs/zAJSL/module/W7Contact/src/W7Contact/Model/Model.php(99): AcMailer\Service\MailService->send() #7 /homepages/43/d387176596/htdocs/zAJSL/module/W7Contact/src/W7Contact/Controller/IndexController.php(117): W7Contact\Model\Model->sendContactEmail(数组) #8 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83) : W7Contact\Controller\IndexController->indexAction() #9 [内部函数]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) #10 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( 468): call_user_func(数组, 对象(Zend\Mvc\MvcEvent)) #11 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包)) #12 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(116): Zend\EventManager\EventManager->触发器('dispatch', 对象( Zend\Mvc\MvcEvent), Object(Closure)) #13 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(113): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response)) #14 [内部函数]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)) #15 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(数组, 对象(Zend\Mvc\MvcEvent)) #16 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包) ) #17 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->触发器('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包)) #18 /homepages/43/d387176596/htdocs/zAJSL/public/index.php(40): Zend\Mvc\Application->运行() #19 {main}
2017 年 3 月 19 日更新
我在这里找到了配置:
/vendor/acelaya/zf2-acmailer/config
那里有 2 个文件
module.config.php & mail.global.php.dist
mail.global.php.dist 似乎有一些我试过但似乎没有帮助的配置选项。我需要将其设置为使用以下 imap 设置:
设置 IMAP
接收服务器 imap.1and1.co.uk
启用 SSL 的端口 993
发送服务器 (SMTP) auth.smtp.1and1.co.uk
启用 TLS 的传出端口 587
发送服务器需要身份验证
(用户名和密码)?是
这是文件
'mail_options' => array(
/***********
* ADAPTER *
***********/
/*
* The mail adapter to be used.
* You can define any class implementing Zend\Mail\Transport\TransportInterface,
* either the class fully qualified name or the instance to be used.
* For standard mail transports, you can use aliases,
* - sendmail => Zend\Mail\Transport\Sendmail
* - smtp => Zend\Mail\Transport\Smtp
* - file => Zend\Mail\Transport\File
* - null => Zend\Mail\Transport\Null
* Default value is Zend\Mail\Transport\Sendmail
*/
//'mail_adapter' => 'Zend\Mail\Transport\Sendmail',
/*
* A service name which will return a Zend\Mail\Transport\TransportInterface instance to be used as the
* transport object.
* If this is set to something other than null, the 'mail_adapter' option will be ignored
* Default value is null
*
* Note: Many configuration options are useful for standard transport objects only.
* The mail_dapater_service is usefull to configure your own transport object with custom options
*/
//'mail_adapter_service' => null,
/************************
* COMMON CONFIGURATION *
************************/
/*
* From email address of the email.
* It would be used as SMTP username if mail_adapter is set to Zend\Mail\Transport\Smtp
* and no smtp_user is provided
* Default value is an empty string
*/
//'from' => '',
/*
* From name to be displayed instead of from address.
* Default value is an empty string
*/
//'from_name' => '',
/*
* Destination addresses of sent emails. It can be an email address as string or an array of email addresses.
* Default value is an empty array.
*/
//'to' => array(),
/*
* Copy destination addresses of sent emails.
* It can be an email address as string or an array of email addresses.
* Default value is an empty array
*/
//'cc' => array(),
/*
* Hidden copy destination addresses of sent emails.
* It can be an email address as string or an array of email addresses.
* Default value is an empty array
*/
//'bcc' => array(),
/*
* Email subject.
* Default value is an empty string
*/
//'subject' => '',
/*
* Email body. Can be a string or hardcoded HTML.
* If a more complex value is nedded it will have to be done in the code.
* Default value is an empty string.
*/
//'body' => '',
/*
* The charset to be set to the body when setting an HTML string body.
* It will be ignored if the body is a plain text string.
* Default value is 'utf-8'.
*/
//'body_charset' => 'utf-8',
/*
* Defines information to create the email body from a view partial.
* It defines template path and template params.
* The path will be resolved by a view resolver, so you need to place mail templates inside a view
* folder of one of your modules or customize your template map and template path stack.
* Params will be a group of key-value pairs.
* It has a use_template property wich tells if template should be used automatically,
* ignoring anything defined at 'body' option. It is false by default.
*
* The 'children' property allows to define children for the template, in case you want to use layouts.
* You can define any number of children. The key is the 'capture_to' property.
* If you set the key 'content' to the child, you should have something like echo $this->content in you layout.
* Any child can have its own children, so you can nest views into other views recursively.
* By default no children are used
*/
//'template' => array(
// 'use_template' => false,
// 'path' => 'ac-mailer/mail-templates/layout',
// 'params' => array(),
// 'children' => array(
// 'content' => array(
// 'path' => 'ac-mailer/mail-templates/mail',
// 'params' => array(),
// )
// )
//),
/*
* Attachments config.
* Allows to define an array of files that will be attached to the message,
* or even a directory that will be iterated to attach all found files.
* Set directory will only be iterated if 'iterate' property is true and 'path' is a valid directory.
* If 'recursive' is true all nested directories will be iterated too.
* If both files and dir are set, all files will be merged without duplication
* By default the files array is empty and the directory won't be iterated
*/
//'attachments' => array(
// 'files' => array(),
// 'dir' => array(
// 'iterate' => false,
// 'path' => 'data/mail/attachments',
// 'recursive' => false,
// ),
//),
/**********************
* SMTP CONFIGURATION *
**********************/
/*
* Hostname or IP address of mail server to be used.
* Default value is localhost
*/
'server' => 'auth.smtp.1and1.co.uk',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP authentication identity.
* If this is not set, from option is used.
* Default value is an empty string
*/
'smtp_user' => '****@****.co.uk',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP authentication credential.
* Default value is an empty string
*/
'smtp_password' => '********',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this defines the SSL type to be used, 'ssl' or 'tls'.
* Boolean false should be used to disable SSL.
* Default value is false
*/
'ssl' => true,
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the connection class used for authentication.
* Value can be one of 'smtp', 'plain', 'login' or 'crammd5'.
* Default value is login. ZF2 default is smtp
*/
//'connection_class' => 'login',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP server port
*/
'port' => 993,
/**********************
* FILE CONFIGURATION *
**********************/
/*
* If Zend\Mail\Transport\File adapter is used, thi sis the folder where the file is going to be saved
* Default value is 'data/mail/output'
*/
//'file_path' => 'data/mail/output',
/**
* A callable that will get the Zend\Mail\Transport\File object as an argument and should return the filename
* Default value is null, in which case a default callable will be used
*/
//'file_callback' => null,
)
);
基本上,Zend Framework 2/3 将加载 config/autoload/.local.php 和 config/autoload/.[ 中的任何配置文件。 =20=](先全局,后局部,所以局部可以覆盖全局)。
在你的情况下,你需要从你的文件中删除 .dist
,然后将你给我的设置放入。实际上,你甚至应该在本地文件中设置这些设置取决于您的环境。
万一有人看到这个并且有同样的问题,真正的问题是:
错误:
'mail_adapter' => 'Zend\Mail\Transport\smtp',
正确:'mail_adapter' => 'Zend\Mail\Transport\Sendmail',
1and1 使用 sendmail 而不是 smtp。
对于 1and1,您需要这些设置:
'server' => 'auth.smtp.1and1.co.uk',
'ssl' => 'tls',
'connection_class' => 'smtp',
'port' => 587,
用户名是您的电子邮件,其他设置不言而喻。
再次感谢 Thomas 在正确的方向上帮助我。我花了 4 天的大部分时间研究这个问题,所以我希望这能找到其他需要它的人。
干杯
我继承了一个使用 zend framework 2 构建的客户网站。我已经弄清楚如何将它移动到我的主机上,这很好,但仍然存在一个问题,那就是电子邮件联系表。通过联系表发送电子邮件时,出现以下错误。我怀疑它是一个配置区域,但在我想知道是否有人可以指出我正确的方向来修复这个错误之前我没有使用过这个系统。
干杯
发生错误。异常:\n #0 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(149): Zend\Mail\Protocol\AbstractProtocol->_connect('tcp://auth.smtp...') #1 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php( 340): Zend\Mail\Protocol\Smtp->connect() #2 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(326): Zend\Mail\Transport\Smtp->connect() #3 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(337): Zend\Mail\Transport\Smtp->lazyLoadConnection() #4 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(204): Zend\Mail\Transport\Smtp->connect() #5 /homepages/43/d387176596/htdocs/zAJSL/vendor/acelaya/zf2-acmailer/src/Service/MailService.php(88): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message)) #6 /homepages/43/d387176596/htdocs/zAJSL/module/W7Contact/src/W7Contact/Model/Model.php(99): AcMailer\Service\MailService->send() #7 /homepages/43/d387176596/htdocs/zAJSL/module/W7Contact/src/W7Contact/Controller/IndexController.php(117): W7Contact\Model\Model->sendContactEmail(数组) #8 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83) : W7Contact\Controller\IndexController->indexAction() #9 [内部函数]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) #10 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( 468): call_user_func(数组, 对象(Zend\Mvc\MvcEvent)) #11 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包)) #12 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(116): Zend\EventManager\EventManager->触发器('dispatch', 对象( Zend\Mvc\MvcEvent), Object(Closure)) #13 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(113): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response)) #14 [内部函数]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)) #15 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(数组, 对象(Zend\Mvc\MvcEvent)) #16 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包) ) #17 /homepages/43/d387176596/htdocs/zAJSL/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->触发器('dispatch', 对象(Zend\Mvc\MvcEvent), 对象(闭包)) #18 /homepages/43/d387176596/htdocs/zAJSL/public/index.php(40): Zend\Mvc\Application->运行() #19 {main}
2017 年 3 月 19 日更新
我在这里找到了配置:
/vendor/acelaya/zf2-acmailer/config
那里有 2 个文件
module.config.php & mail.global.php.dist
mail.global.php.dist 似乎有一些我试过但似乎没有帮助的配置选项。我需要将其设置为使用以下 imap 设置:
设置 IMAP
接收服务器 imap.1and1.co.uk
启用 SSL 的端口 993
发送服务器 (SMTP) auth.smtp.1and1.co.uk
启用 TLS 的传出端口 587
发送服务器需要身份验证
(用户名和密码)?是
这是文件
'mail_options' => array(
/***********
* ADAPTER *
***********/
/*
* The mail adapter to be used.
* You can define any class implementing Zend\Mail\Transport\TransportInterface,
* either the class fully qualified name or the instance to be used.
* For standard mail transports, you can use aliases,
* - sendmail => Zend\Mail\Transport\Sendmail
* - smtp => Zend\Mail\Transport\Smtp
* - file => Zend\Mail\Transport\File
* - null => Zend\Mail\Transport\Null
* Default value is Zend\Mail\Transport\Sendmail
*/
//'mail_adapter' => 'Zend\Mail\Transport\Sendmail',
/*
* A service name which will return a Zend\Mail\Transport\TransportInterface instance to be used as the
* transport object.
* If this is set to something other than null, the 'mail_adapter' option will be ignored
* Default value is null
*
* Note: Many configuration options are useful for standard transport objects only.
* The mail_dapater_service is usefull to configure your own transport object with custom options
*/
//'mail_adapter_service' => null,
/************************
* COMMON CONFIGURATION *
************************/
/*
* From email address of the email.
* It would be used as SMTP username if mail_adapter is set to Zend\Mail\Transport\Smtp
* and no smtp_user is provided
* Default value is an empty string
*/
//'from' => '',
/*
* From name to be displayed instead of from address.
* Default value is an empty string
*/
//'from_name' => '',
/*
* Destination addresses of sent emails. It can be an email address as string or an array of email addresses.
* Default value is an empty array.
*/
//'to' => array(),
/*
* Copy destination addresses of sent emails.
* It can be an email address as string or an array of email addresses.
* Default value is an empty array
*/
//'cc' => array(),
/*
* Hidden copy destination addresses of sent emails.
* It can be an email address as string or an array of email addresses.
* Default value is an empty array
*/
//'bcc' => array(),
/*
* Email subject.
* Default value is an empty string
*/
//'subject' => '',
/*
* Email body. Can be a string or hardcoded HTML.
* If a more complex value is nedded it will have to be done in the code.
* Default value is an empty string.
*/
//'body' => '',
/*
* The charset to be set to the body when setting an HTML string body.
* It will be ignored if the body is a plain text string.
* Default value is 'utf-8'.
*/
//'body_charset' => 'utf-8',
/*
* Defines information to create the email body from a view partial.
* It defines template path and template params.
* The path will be resolved by a view resolver, so you need to place mail templates inside a view
* folder of one of your modules or customize your template map and template path stack.
* Params will be a group of key-value pairs.
* It has a use_template property wich tells if template should be used automatically,
* ignoring anything defined at 'body' option. It is false by default.
*
* The 'children' property allows to define children for the template, in case you want to use layouts.
* You can define any number of children. The key is the 'capture_to' property.
* If you set the key 'content' to the child, you should have something like echo $this->content in you layout.
* Any child can have its own children, so you can nest views into other views recursively.
* By default no children are used
*/
//'template' => array(
// 'use_template' => false,
// 'path' => 'ac-mailer/mail-templates/layout',
// 'params' => array(),
// 'children' => array(
// 'content' => array(
// 'path' => 'ac-mailer/mail-templates/mail',
// 'params' => array(),
// )
// )
//),
/*
* Attachments config.
* Allows to define an array of files that will be attached to the message,
* or even a directory that will be iterated to attach all found files.
* Set directory will only be iterated if 'iterate' property is true and 'path' is a valid directory.
* If 'recursive' is true all nested directories will be iterated too.
* If both files and dir are set, all files will be merged without duplication
* By default the files array is empty and the directory won't be iterated
*/
//'attachments' => array(
// 'files' => array(),
// 'dir' => array(
// 'iterate' => false,
// 'path' => 'data/mail/attachments',
// 'recursive' => false,
// ),
//),
/**********************
* SMTP CONFIGURATION *
**********************/
/*
* Hostname or IP address of mail server to be used.
* Default value is localhost
*/
'server' => 'auth.smtp.1and1.co.uk',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP authentication identity.
* If this is not set, from option is used.
* Default value is an empty string
*/
'smtp_user' => '****@****.co.uk',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP authentication credential.
* Default value is an empty string
*/
'smtp_password' => '********',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this defines the SSL type to be used, 'ssl' or 'tls'.
* Boolean false should be used to disable SSL.
* Default value is false
*/
'ssl' => true,
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the connection class used for authentication.
* Value can be one of 'smtp', 'plain', 'login' or 'crammd5'.
* Default value is login. ZF2 default is smtp
*/
//'connection_class' => 'login',
/*
* If Zend\Mail\Transport\Smtp adapter is used, this is the SMTP server port
*/
'port' => 993,
/**********************
* FILE CONFIGURATION *
**********************/
/*
* If Zend\Mail\Transport\File adapter is used, thi sis the folder where the file is going to be saved
* Default value is 'data/mail/output'
*/
//'file_path' => 'data/mail/output',
/**
* A callable that will get the Zend\Mail\Transport\File object as an argument and should return the filename
* Default value is null, in which case a default callable will be used
*/
//'file_callback' => null,
)
);
基本上,Zend Framework 2/3 将加载 config/autoload/.local.php 和 config/autoload/.[ 中的任何配置文件。 =20=](先全局,后局部,所以局部可以覆盖全局)。
在你的情况下,你需要从你的文件中删除 .dist
,然后将你给我的设置放入。实际上,你甚至应该在本地文件中设置这些设置取决于您的环境。
万一有人看到这个并且有同样的问题,真正的问题是:
错误: 'mail_adapter' => 'Zend\Mail\Transport\smtp',
正确:'mail_adapter' => 'Zend\Mail\Transport\Sendmail',
1and1 使用 sendmail 而不是 smtp。
对于 1and1,您需要这些设置:
'server' => 'auth.smtp.1and1.co.uk',
'ssl' => 'tls',
'connection_class' => 'smtp',
'port' => 587,
用户名是您的电子邮件,其他设置不言而喻。
再次感谢 Thomas 在正确的方向上帮助我。我花了 4 天的大部分时间研究这个问题,所以我希望这能找到其他需要它的人。
干杯