本文整理匯總了PHP中Zend\Mail\Transport\Smtp類的典型用法代碼示例。如果您正苦於以下問題:PHP Smtp類的具體用法?PHP Smtp怎麽用?PHP Smtp使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Smtp類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: send
protected function send()
{
try {
$message = new Message();
$para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"])));
$message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]);
$transport = new SmtpTransport();
$options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => 'dispatch@pessoaweb.com.br', 'password' => 'd1i2s3p4atch'), 'port' => 587));
$html = new MimePart($this->dados["body"]);
$html->type = "text/html";
$html->charset = "UTF-8";
$body = new MimeMessage();
if (isset($this->dados["attachment"])) {
foreach ($this->dados["attachment"] as $valor) {
$attachment = new MimePart($valor["arquivo"]);
$attachment->filename = $valor["titulo"];
if (isset($valor["tipo"])) {
$attachment->type = $valor["tipo"];
}
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime::ENCODING_BASE64;
$body->setParts(array($attachment));
}
}
$body->addPart($html);
$message->setBody($body);
$transport->setOptions($options);
$transport->send($message);
return $transport;
} catch (\Exception $e) {
debug(array("email" => $e->getMessage()), true);
}
}
示例2: sendMessage
public function sendMessage(Message $message, Smtp $smtp, $recipient)
{
$message->addTo($recipient);
if (!$this->config['disable_delivery']) {
$smtp->send($message);
}
}
示例3: sendEmail
private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg)
{
$renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $renderer->render('email/template', array('msg' => nl2br($msg)));
// make a header as html(template)
$html = new MimePart($content);
$html->type = "text/html";
// make a image inline
$image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r'));
$image->type = "image/jpeg";
$image->id = "fundo_mail";
$image->disposition = "inline";
// build an email with a text(html) + image(inline)
$body = new MimeMessage();
$body->setParts(array($html, $image));
// instance mail
$mail = new Mail\Message();
$mail->setBody($body);
// will generate our code html from template.phtml
$mail->setFrom($this->from['email'], utf8_decode($this->from['nome']));
$mail->addTo($listaEmailTo);
//$mail->addCc($listaEmailCC);
$mail->setSubject(utf8_decode($subject));
$transport = new Mail\Transport\Smtp($this->options);
try {
$transport->send($mail);
} catch (RuntimeException $exc) {
$this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString());
if ($exc->getMessage() == 'Could not open socket') {
throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!');
}
throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!");
}
}
示例4: getTransport
public function getTransport()
{
$transport = new SmtpTransport();
$options = new SmtpOptions(array('name' => 'bitweb.ee', 'host' => 'smtp.gmail.com', 'port' => '25', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => 'kristjan.andresson@bitweb.ee', 'password' => 'erkinool123')));
$transport->setOptions($options);
return $transport;
}
示例5: getMailerObject
public static function getMailerObject()
{
$response = array();
$response['mail'] = new Message();
$response['mail']->setEncoding(APP_CHARSET);
if (strcasecmp(Config::get('concrete.mail.method'), 'smtp') == 0) {
$config = array('host' => Config::get('concrete.mail.methods.smtp.server'));
$username = Config::get('concrete.mail.methods.smtp.username');
$password = Config::get('concrete.mail.methods.smtp.password');
if ($username != '') {
$config['connection_class'] = 'login';
$config['connection_config'] = array();
$config['connection_config']['username'] = $username;
$config['connection_config']['password'] = $password;
}
$port = Config::get('concrete.mail.methods.smtp.port', '');
if ($port != '') {
$config['port'] = $port;
}
$encr = Config::get('concrete.mail.methods.smtp.encryption', '');
if ($encr != '') {
$config['connection_config']['ssl'] = $encr;
}
$transport = new SmtpTransport();
$options = new SmtpOptions($config);
$transport->setOptions($options);
$response['transport'] = $transport;
} else {
$response['transport'] = new SendmailTransport();
}
return $response;
}
示例6: createService
/**
* Create service
*
* @param ServiceLocatorInterface $sm Service manager
*
* @return mixed
*/
public function createService(ServiceLocatorInterface $sm)
{
// Load configurations:
$config = $sm->get('VuFind\\Config')->get('config');
// Create mail transport:
$settings = ['host' => $config->Mail->host, 'port' => $config->Mail->port];
if (isset($config->Mail->username) && isset($config->Mail->password)) {
$settings['connection_class'] = 'login';
$settings['connection_config'] = ['username' => $config->Mail->username, 'password' => $config->Mail->password];
if (isset($config->Mail->secure)) {
// always set user defined secure connection
$settings['connection_config']['ssl'] = $config->Mail->secure;
} else {
// set default secure connection based on configured port
if ($settings['port'] == '587') {
$settings['connection_config']['ssl'] = 'tls';
} elseif ($settings['port'] == '487') {
$settings['connection_config']['ssl'] = 'ssl';
}
}
}
$transport = new Smtp();
$transport->setOptions(new SmtpOptions($settings));
// Create service:
return new \VuFind\Mailer\Mailer($transport);
}
示例7: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');
$transport = new Smtp();
$transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
return $transport;
}
示例8: getTransport
public function getTransport()
{
$transport = new SmtpTransport();
$options = new SmtpOptions(array('name' => 'localhost.localdomain', 'host' => $this->smtpHost, 'connection_class' => 'login', 'connection_config' => array('username' => $this->smtpUser, 'password' => $this->smtpPass)));
$transport->setOptions($options);
return $transport;
}
示例9: send
public function send($subject, $text, $to, $from = null)
{
if (!config('mail.enabled')) {
return;
}
$message = new Message();
$message->setSubject($subject);
if ($from) {
if (is_array($from)) {
$message->setFrom($from[0], $from[1]);
} else {
$message->setFrom($from);
}
}
$message->addTo($to);
$content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
$html = new Mime\Part($content);
$html->setType(Mime\Mime::TYPE_HTML);
$html->setCharset('utf-8');
$mimeMessage = new Mime\Message();
$mimeMessage->addPart($html);
foreach ($this->attachments as $attachment) {
$mimeMessage->addPart($attachment);
}
$message->setBody($mimeMessage);
try {
$transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
$transport->send($message);
} catch (\Exception $e) {
throw $e;
}
return $this;
}
示例10: sendMail
/**
* Sends a mail with the given data from the AppMailAccount
* @param string $to
* @param string $subject
* @param string $content
*/
public function sendMail(string $to, string $subject, string $content, array $files = [])
{
$content .= "\n\nThis is an automated mail. Please don't respond.";
$text = new Mime\Part($content);
$text->type = 'text/plain';
$text->charset = 'utf-8';
$text->disposition = Mime\Mime::DISPOSITION_INLINE;
$parts[] = $text;
foreach ($files as $filePath) {
$fileContent = file_get_contents($filePath);
$attachment = new Mime\Part($fileContent);
$attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
$attachment->filename = basename($filePath);
$attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime\Mime::ENCODING_BASE64;
$parts[] = $attachment;
}
$mime = new Mime\Message();
$mime->setParts($parts);
$appMailData = $this->getAppMailData();
$message = new Message();
$message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
$transport = new SmtpTransport();
$options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
$transport->setOptions($options);
$transport->send($message);
}
示例11: run
public function run()
{
$transport = new SmtpTransport(new SmtpOptions(array('name' => $this->host, 'host' => $this->host, 'port' => $this->port, 'connection_config' => array('username' => $this->sender->getUsername(), 'password' => $this->sender->getPassword()))));
if ($this->auth !== null) {
$transport->getOptions()->setConnectionClass($this->auth);
}
$message = new Message();
$message->addFrom($this->sender->getUsername())->setSubject($this->subject);
if ($this->bcc) {
$message->addBcc($this->recipients);
} else {
$message->addTo($this->recipients);
}
$body = new MimeMessage();
if ($this->htmlBody == null) {
$text = new MimePart($this->textBody);
$text->type = "text/plain";
$body->setParts(array($text));
} else {
$html = new MimePart($this->htmlBody);
$html->type = "text/html";
$body->setParts(array($html));
}
$message->setBody($body);
$transport->send($message);
}
示例12: __construct
/**
* Prepares the \Zend\Mail module
*/
public function __construct()
{
$beehubConfig = \BeeHub::config();
$config = $beehubConfig['email'];
if (!empty($config['host'])) {
// Configure the transporter for sending through SMTP
$transport = new Mail\Transport\Smtp();
$emailConfig = array('host' => $config['host']);
if (!empty($config['port'])) {
$emailConfig['port'] = $config['port'];
}
if (!empty($config['security'])) {
$emailConfig['connection_config'] = array();
$emailConfig['connection_config']['ssl'] = $config['security'];
}
if (!empty($config['auth_method'])) {
$emailConfig['connection_class'] = $config['auth_method'];
if (!isset($emailConfig['connection_config'])) {
$emailConfig['connection_config'] = array();
}
$emailConfig['connection_config']['username'] = $config['username'];
$emailConfig['connection_config']['password'] = $config['password'];
}
$options = new Mail\Transport\SmtpOptions($emailConfig);
$transport->setOptions($options);
} else {
// Else we use the Sendmail transporter (which actually just uses mail()
$transport = new Mail\Transport\Sendmail();
}
$this->emailer = $transport;
}
示例13: sendNotificationMail
/**
* W momencie zapisu lokalizacji do bazy – wysyła się e-mail na stały adres administratora
* serwisu z powiadomieniem o dodaniu nowej lokalizacji (nazwa miejsca + link do strony na froncie serwisu)
*
* @param Entity\Location $location
*/
public function sendNotificationMail(Entity\Location $location)
{
/**
* dane do wysylanego maila z potwierdzeniem, zdefiniowane w module.config.php
*/
$config = $this->getServiceManager()->get('Config')['configuration']['location_mail_notification'];
/* blokada wysylania maila (do testow) */
if (false === $config['send_notification_mail']) {
return false;
}
$uri = $this->getServiceManager()->get('request')->getUri();
/* @var $uri \Zend\Uri\Http */
$route = $this->getServiceManager()->get('router')->getRoute('location-details');
/* @var $route \Zend\Mvc\Router\Http\Segment */
/**
* link do nowej lokalizacji
*/
$base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
$url = $route->assemble(array('id' => $location->getId()));
$mailConfig = (object) $config['message_config'];
$html = strtr($mailConfig->message, array('%name%' => $location->getName(), '%link%' => $base . $url));
$message = new Mime\Message();
$message->setParts(array((new Mime\Part($html))->setType('text/html')));
$mail = new Mail\Message();
$mail->setBody($message)->setFrom($mailConfig->from_email, $mailConfig->from_name)->addTo($mailConfig->to_email, $mailConfig->to_name)->setSubject($mailConfig->subject);
$transport = new Mail\Transport\Smtp(new Mail\Transport\SmtpOptions($config['smtp_config']));
$transport->send($mail);
}
示例14: send
/**
* @param Message $message
*/
public function send(Message $message)
{
if (!count($message->getFrom())) {
$message->setFrom('no-reply@uscaninescentsports.com', 'US Canine Scent Sports');
}
$transport = new Transport\Smtp();
$transport->setOptions($this->transportOptions)->send($message);
}
示例15: flush
public function flush()
{
$this->transport->setOptions($this->getSmtpOptions());
foreach ($this->queue as $message) {
$this->transport->send($message);
}
$this->queue = [];
}