PHP zf2 邮件 return 空
PHP zf2 mail return null
我尝试用 ZF2 发送电子邮件。
我使用:
$mail = new Mail\Message();
$mail->addFrom('email@mail.com', 'name')
->addTo('email@mail.com')
->setSubject('Cotización')->setBody('This is the text of the mail.');
try{
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
}catch (\Exception $e)
{
//var_dump($e);
}
die();
我总是"null"。在 HTML 我得到:
<pre class="xdebug-var-dump" dir="ltr"><font color="#3465a4">null</font>
但是我收到 var_dump 的评论并且我设置了 die();但打印我的文字。我真的不知道该如何解决。
PD:没有进入异常。我尝试打印文本。
试试这个:
//mail
use Zend\Mail\Message;
use Zend\Mail\Transport\Sendmail as SendmailTransport;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
.....
function sendEmail($mail){
/*
*Optional; email with style
*
*/
$this->renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $this->renderer->render('application/index/mail',array());
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html));
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
/*
*Optional; email with style
*
*/
$transport = $this->getServiceLocator()->get('mail.transport');
$message = new Message();
$message->getHeaders()->addHeaderLine($cabeceras);
$this->getRequest()->getServer(); //Server vars
$message->addTo($mail)
->addFrom('test@gmail.com')
->setSubject('TestSubject')
->setEncoding("UTF-8")
->setBody($body);
$transport = new SendmailTransport();
$transport->send($message);
}
我尝试用 ZF2 发送电子邮件。
我使用:
$mail = new Mail\Message();
$mail->addFrom('email@mail.com', 'name')
->addTo('email@mail.com')
->setSubject('Cotización')->setBody('This is the text of the mail.');
try{
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
}catch (\Exception $e)
{
//var_dump($e);
}
die();
我总是"null"。在 HTML 我得到:
<pre class="xdebug-var-dump" dir="ltr"><font color="#3465a4">null</font>
但是我收到 var_dump 的评论并且我设置了 die();但打印我的文字。我真的不知道该如何解决。 PD:没有进入异常。我尝试打印文本。
试试这个:
//mail
use Zend\Mail\Message;
use Zend\Mail\Transport\Sendmail as SendmailTransport;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
.....
function sendEmail($mail){
/*
*Optional; email with style
*
*/
$this->renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $this->renderer->render('application/index/mail',array());
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html));
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
/*
*Optional; email with style
*
*/
$transport = $this->getServiceLocator()->get('mail.transport');
$message = new Message();
$message->getHeaders()->addHeaderLine($cabeceras);
$this->getRequest()->getServer(); //Server vars
$message->addTo($mail)
->addFrom('test@gmail.com')
->setSubject('TestSubject')
->setEncoding("UTF-8")
->setBody($body);
$transport = new SendmailTransport();
$transport->send($message);
}