我正在尝试使用zend / Mail
通过smtp选项发送电子邮件这是我的代码:
//use the base class
use Zend\Mail;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
这是我在控制器中的邮件功能代码
//mail functionality
$email = "xxxx@gmail.com";
$pas = "xxxx";
// setup SMTP options
$options = new Mail\Transport\SmtpOptions(array(
'name' => 'localhost',
'host' => 'smtp.gmail.com',
'port'=> 587,
'connection_class' => 'login',
'connection_config' => array(
'username' => $email,
'password' => $pas,
'ssl'=> 'tls',
),
));
$this->renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $this->renderer->render('patient-register/email/template', null);
// make a header as html
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html,));
// instance mail
$mail = new Mail\Message();
$mail->setBody($body); // will generate our code html from template.phtml
$mail->setFrom('xxxx@xxxx.com','mub');
$mail->setTo('xxxx@gmail.com');
$mail->setSubject('TESTING THE EMAIL ACCCOUNT');
$transport = new Mail\Transport\Smtp($options);
$transport->send($mail);
因此,当我尝试从我的localhost发送邮件时,它就成功了
但是当我尝试从远程服务器发送电子邮件时,128.199.123.145并且服务器是来自digitalocean的centos服务器。
远程服务器是否有任何改变。
谢谢,