我试图发送一封电子邮件与ZendMail(这个简单的脚本总结)
但是我得到这个堆栈跟踪:
- Fatal error: Uncaught exception 'Zend_Mail_Transport_Exception' with message 'Unable to send mail. ' in /usr/share/PHP/libzend-framework-PHP/Zend/Mail/Transport/Sendmail.PHP:137 Stack trace: #0 /usr/share/PHP/libzend-framework-PHP/Zend/Mail/Transport/Abstract.PHP(348): Zend_Mail_Transport_Sendmail->_sendMail() #1 /usr/share/PHP/libzend-framework-PHP/Zend/Mail.PHP(1178): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail)) #2 /var/www/hexreaction/mail/index2.PHP(11): Zend_Mail->send() #3 {main} thrown in /usr/share/PHP/libzend-framework-PHP/Zend/Mail/Transport/Sendmail.PHP on line 137
编辑:
我不是想使用SMTP发送我的电子邮件,而且我有一个不太可怕的问题,但仍然是一个问题.
- <?PHP
- require_once 'Zend/Mail.PHP';
- $config = array('auth' => 'login','username' => 'contact@mypage.com','password' => 'secretpass');
- $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
- $mail = new Zend_Mail();
- $mail->setBodyText('This is the text of the mail.');
- $mail->setFrom('contact@mypage.com','Some Sender');
- $mail->addTo('contact@mypage.com','Some Recipient');
- $mail->setSubject('TestSubject');
- $mail->send($transport);
- ?>
这个抛出的这个错误,我真的不明白为什么:
- Fatal error: Class 'Zend_Mail_Transport_Smtp' not found in /var/www/hexreaction/mail/index3.PHP on line 7
编辑2:
这是我最后的工作代码
- require_once('Zend/Mail/Transport/Smtp.PHP');
- require_once 'Zend/Mail.PHP';
- $config = array('auth' => 'login','username' => 'somemail@mysite.com','password' => 'somepass','ssl' => 'tls');
- $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
- $mail = new Zend_Mail();
- $mail->setBodyText('This is the text of the mail.');
- $mail->setFrom('somemail@mysite.com','Some Sender');
- $mail->addTo('somemail@mysite.com','Some Recipient');
- $mail->setSubject('TestSubject');
- $mail->send($transport);
正如你在Stack trace中看到的那样,Zend_Mail使用Zend_Mail_Transport_Sendmail作为传输适配器.
因此,请确保您的系统上运行的是与邮件兼容的 MTA(如Postfix).
因此,请确保您的系统上运行的是与邮件兼容的 MTA(如Postfix).
作为替代方案,您可以使用Zend_Mail_Transport_Smtp传输适配器,并使用外部SMTP服务器
- $tr = new Zend_Mail_Transport_Smtp('mail.example.com',array(
- 'auth' => 'login','username' => $username,'password' => $password,'port' => $port,));
- Zend_Mail::setDefaultTransport($tr);
编辑:
对于你的第二个问题:a
require_once( ‘的Zend /邮件/运输/ Smtp.PHP’);
应该有帮助.