Example #1
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  *
  * @return bool true/false if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name)
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->mail->setFrom($sender, $name);
         $this->mail->setSubject($subject);
         $this->mail->setBody($body, 'text/html');
         $this->mail->setTo($recipient);
         $this->mail->send();
         return $this->mail->isSent();
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  * @param array $attachments Array of files (e.g. ['/absolute/path/doc.pdf'])
  *
  * @return bool TRUE/FALSE if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name = null, $attachments = [])
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->initialize();
         $this->mailer->setFrom($sender, $name);
         $this->mailer->setSubject($subject);
         $this->mailer->setBody($body, 'text/html');
         $this->mailer->setTo($recipient);
         $this->addAttachments($attachments);
         $this->mailer->send();
         return $this->mailer->isSent();
     } else {
         return false;
     }
 }
 /**
  * Sets the sender of the mail message
  *
  * Mostly the sender is a combination of the name and the email address
  *
  * @return void
  */
 protected function setFrom()
 {
     if (isset($this->typoScript['senderEmail'])) {
         $fromEmail = $this->formUtility->renderItem($this->typoScript['senderEmail.'], $this->typoScript['senderEmail']);
     } elseif ($this->getTypoScriptValueFromIncomingData('senderEmailField') !== null) {
         $fromEmail = $this->getTypoScriptValueFromIncomingData('senderEmailField');
     } else {
         $fromEmail = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
     }
     if (!GeneralUtility::validEmail($fromEmail)) {
         $fromEmail = MailUtility::getSystemFromAddress();
     }
     if (isset($this->typoScript['senderName'])) {
         $fromName = $this->formUtility->renderItem($this->typoScript['senderName.'], $this->typoScript['senderName']);
     } elseif ($this->getTypoScriptValueFromIncomingData('senderNameField') !== null) {
         $fromName = $this->getTypoScriptValueFromIncomingData('senderNameField');
     } else {
         $fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
     }
     $fromName = $this->sanitizeHeaderString($fromName);
     if (!empty($fromName)) {
         $from = array($fromEmail => $fromName);
     } else {
         $from = $fromEmail;
     }
     $this->mailMessage->setFrom($from);
 }
 /**
  * Sets the sender of the mail message
  *
  * Mostly the sender is a combination of the name and the email address
  *
  * @return void
  */
 protected function setFrom()
 {
     $fromEmail = '';
     if ($this->typoScript['senderEmail']) {
         $fromEmail = $this->typoScript['senderEmail'];
     } elseif ($this->requestHandler->has($this->typoScript['senderEmailField'])) {
         $fromEmail = $this->requestHandler->get($this->typoScript['senderEmailField']);
     } else {
         $fromEmail = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
     }
     if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($fromEmail)) {
         $fromEmail = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFromAddress();
     }
     $fromName = '';
     if ($this->typoScript['senderName']) {
         $fromName = $this->typoScript['senderName'];
     } elseif ($this->requestHandler->has($this->typoScript['senderNameField'])) {
         $fromName = $this->requestHandler->get($this->typoScript['senderNameField']);
     } else {
         $fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
     }
     $fromName = $this->sanitizeHeaderString($fromName);
     if (preg_match('/\\s|,/', $fromName) >= 1) {
         $fromName = '"' . $fromName . '"';
     }
     $from = array($fromEmail => $fromName);
     $this->mailMessage->setFrom($from);
 }
 /**
  * send email on new/update.
  *
  * @param string                                    $subjectKey
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  *
  * @return int The amound of email receivers
  */
 public function sendMail($subjectKey, \JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     $this->view->assign('club', $club);
     $this->mail->setFrom($this->extConf->getEmailFromAddress(), $this->extConf->getEmailFromName());
     $this->mail->setTo($this->extConf->getEmailToAddress(), $this->extConf->getEmailToName());
     $this->mail->setSubject(LocalizationUtility::translate('email.subject.' . $subjectKey, 'clubdirectory'));
     $this->mail->setBody($this->view->render(), 'text/html');
     return $this->mail->send();
 }
 /**
  * Sets the name and email of the "From" header.
  *
  * The function name setSender is misleading since there is
  * also a "Sender" header which is not set by this method
  *
  * @param string $email
  * @param string $name
  */
 public function setSender($email, $name)
 {
     if (!empty($email)) {
         $this->emailObj->setFrom($email, $name);
     }
 }
Example #7
0
 /**
  * @param string $data
  * @return MailMessage
  */
 protected function prepareEmail($data)
 {
     $body = $this->getBody();
     $sender = $this->getSender();
     $recipient = $this->getRecipient();
     if (TRUE === is_array($recipient)) {
         list($recipientAddress, $recipientName) = $recipient;
     } else {
         $recipientAddress = $recipient;
         $recipientName = NULL;
     }
     if (TRUE === is_array($sender)) {
         list($senderAddress, $senderName) = $sender;
     } else {
         $senderAddress = $sender;
         $senderName = NULL;
     }
     $subject = $this->getSubject();
     if (TRUE === is_string($data)) {
         $body = $data;
     }
     $message = new MailMessage();
     $message->setSubject($subject);
     $message->setFrom($senderAddress, $senderName);
     $message->setTo($recipientAddress, $recipientName);
     $message->setBody($body);
     return $message;
 }
 /**
  * Sets the sender
  *
  * @param array $sender Sender list (mail -> name)
  *
  * @return void
  */
 public function setSender(array $sender)
 {
     $this->message->setFrom($sender);
 }
Example #9
0
 /**
  * assign mail defaults
  *
  * @return MailView
  */
 protected function assignDefaults()
 {
     $host = GeneralUtility::getIndpEnv('TYPO3_HOST');
     $this->mail->setFrom(array('noreply@' . $host => 'Webseite ' . $host));
     return $this;
 }
Example #10
0
 /**
  * @test
  * @param string|array $addresses
  * @param string|array $expected
  * @dataProvider emailAddressesDataProvider
  */
 public function setFromIdnaEncodesAddresses($addresses, $expected)
 {
     $this->subject->setFrom($addresses);
     $this->assertSame($expected, $this->subject->getFrom());
 }