PHP Method phpmailer\phpmailer\ PHPMailer::setFrom Code Examples

PHP phpmailer\phpmailer\PHPMailer::setFrom - 8 examples found. These are the top rated real world PHP examples of method phpmailer\phpmailer\PHPMailer::setFrom extracted from open source projects. You can rate examples to help us improve the quality of examples

setFrom() public method

Set the From and FromName properties.
public setFrom ( string $address, string $name = '', boolean $auto = true ) : boolean
$address string
$name string
$auto boolean Whether to also set the Sender address, defaults to true
return boolean
Example #1
1
 /**
  *
  * Mauro Cerone
  *
  * @todo read config from file
  */
 public static function startSendOperation()
 {
     /** @var ConfigReader $conf */
     $conf = ConfigReader::getInstance();
     $mailToSend = StesiMailQuery::create()->filterByDeliveryStatus("0")->find();
     foreach ($mailToSend as $mail) {
         try {
             /** @var StesiMail $conf */
             $mailer = new PHPMailer(true);
             $mailer->isHTML(true);
             $mailer->SMTPAuth = true;
             $mailer->isSMTP();
             $mailer->Username = $conf->getUsername();
             $mailer->Password = $conf->getPassword();
             $mailer->Host = $conf->getHost();
             $mailer->Port = $conf->getPort();
             $mailer->SMTPSecure = $conf->getSmtSecure();
             $mailer->setFrom($mail->getFrom());
             $mailer->Subject = $mail->getSubject();
             $arrayA = explode(";", $mail->getA());
             $arrayCC = explode(";", $mail->getCc());
             foreach ($arrayA as $a) {
                 if (!empty($a)) {
                     $mailer->addAddress($a);
                 }
             }
             foreach ($arrayCC as $cc) {
                 if (!empty($cc)) {
                     $mailer->addCC($cc);
                 }
             }
             $mailer->msgHTML($mail->getContent());
             $mailer->send();
             $mail->setDeliveryStatus(1);
         } catch (\Exception $ex) {
             $mail->setDeliveryStatus(-1);
             $mail->setErrorMessage($ex->getMessage());
         } finally {
             $mail->save();
         }
     }
 }
 private function setOptions()
 {
     $this->mailClient->isSMTP();
     $this->mailClient->SMTPAuth = true;
     $this->mailClient->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $this->mailClient->addAddress($this->options->getFrom());
     $this->mailClient->Host = $this->options->getHost();
     $this->mailClient->Username = $this->options->getUserName();
     $this->mailClient->Password = $this->options->getPassword();
     $this->mailClient->setFrom($this->options->getFrom());
     $this->mailClient->Port = $this->options->getPort();
     $this->addCCs();
 }
Example #3
0
 public function sendContactMessage($data)
 {
     if (!isset($data['imienaz']) || empty($data['imienaz']) || !isset($data['email']) || empty($data['email']) || !isset($data['temat']) || empty($data['temat']) || !isset($data['message']) || empty($data['message'])) {
         throw new \Exception('Prosze wypełnić pola formularza');
     }
     $mail = new PHPMailer();
     $mail->isSMTP();
     $mail->Host = 'smtp.emaillabs.net.pl';
     $mail->SMTPAuth = true;
     $mail->Username = '1.matchapp.smtp';
     $mail->Password = 'A&c2X37f';
     $mail->Port = 587;
     $mail->CharSet = 'UTF-8';
     $mail->setFrom($data['email'], $data['imienaz']);
     $mail->addAddress('match@loho.pl');
     // Add a recipient
     $mail->isHTML(false);
     // Set email format to HTML
     $mail->Subject = '[MatchApp] ' . $data['temat'];
     $mail->Body = $data['message'];
     try {
         $mail->send();
     } catch (\Exception $e) {
         throw new \Exception('Wystąpił błąd z wysłaniem wiadomości. ' . $mail->ErrorInfo);
     }
     return true;
 }
Example #4
0
 /**
  * @return $this
  */
 public function from()
 {
     $args = func_get_args();
     if (isset($args[1])) {
         $this->mail->setFrom($args[0], $args[1]);
     } else {
         if (is_array($args[0])) {
             foreach ($args[0] as $name => $address) {
                 $this->mail->setFrom($name, $address);
             }
         }
     }
     return $this;
 }
Example #5
0
 public function indexAction()
 {
     $services = $this->getServiceLocator();
     $config = $services->get('config');
     $translator = $services->get('translator');
     $namespaces = $this->getFlashMessengerNamespaces();
     $user = $this->getAuthInfo();
     $formFactory = new FormFactory();
     $formConfig = $config['feedback']['message_form'];
     if ($user) {
         unset($formConfig['elements']['captcha']);
     }
     $form = $formFactory->createForm($formConfig);
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $mail = new PHPMailer();
             $mail->setFrom($config['feedback']['support_address']);
             $mail->addReplyTo($data['email'], $data['name']);
             $mail->addAddress($config['feedback']['support_address']);
             $subject = $translator->translate($config['feedback']['message_subject']);
             $mail->Subject = str_replace('%name%', $data['name'], $subject);
             $mail->Body = $data['message'];
             $mail->send();
             $this->flashMessenger()->addSuccessMessage($translator->translate('Message was successfully sent. Thanks for feedback'));
             return $this->redirect()->refresh();
         } else {
             $this->flashMessenger()->addMessage($translator->translate('Form has errors. Check it'), $namespaces['error']);
         }
     } else {
         if ($user) {
             $form->get('name')->setValue($user->getDisplayName());
             $form->get('email')->setValue($user->getEmail());
         }
     }
     return array('form' => $form, 'title' => $config['feedback']['title'], 'description' => $config['feedback']['description'], 'display_flash_messages' => $config['feedback']['display_flash_messages']);
 }
Example #6
0
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('Validation', function () use($app) {
    return new Validator($app->user);
});
$app->container->singleton('mail', function () use($app) {
    $mailer = new PHPMailer();
    $mailer->isSMTP();
    $mailer->Host = $app->config->get('mail.host');
    $mailer->SMTPAuth = $app->config->get('mail.smtp_auth');
    $mailer->SMTPSecure = $app->config->get('mail.smtp_secure');
    $mailer->Port = $app->config->get('mail.port');
    $mailer->Username = $app->config->get('mail.username');
    $mailer->Password = $app->config->get('mail.password');
    $mailer->setFrom($app->config->get('mail.username'), $app->config->get('mail.displayname'));
    $mailer->isHTML($app->config->get('mail.html'));
    return new Mailer($app->view, $mailer);
});
$app->container->singleton('randomLib', function () {
    $factory = new RandomLib();
    return $factory->getMediumStrengthGenerator();
});
$view = $app->view();
$view->parserOptions = array('debug' => $app->config->get('twig.debug'));
$view->parserExtensions = array(new TwigExtension());
Example #7
0
function emailsSend($recipients)
{
    $app = new \Slim\Slim();
    $app->db = function () {
        return new Capsule();
    };
    try {
        foreach ($recipients as $recipient) {
            $body = '<div style="display:none; white-space:nowrap; font:15px courier; line-height:0;">
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</div>
<table width="100%" align="center" bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td align="center" valign="top" style="margin: 0; padding: 0;">
            <table width="600" align="center" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0"
                   style="font-family:Arial, Helvetica, sans-serif;">
                <tr>
                    <td align="center" valign="top" style="margin: 0; padding: 0;">
                        <img style="display: block;" src="http://prp.dev.plej.pl/mailing/mailing_header_top.gif" alt="" width="600" height="240">
                    </td>
                </tr>

                <tr>
                    <td style="text-align: center;">

                        <h1 style="font-weight: bold; font-size: 26px; color: #D1AC50; line-height: 38px;">' . $recipient['fullName'] . '</h1>

                        <p style="font-size: 20px; color: #162C53; line-height: 28px;">Wysłaliśmy, specjalnie dla Ciebie zrobioną<br>
                        Kartkę Świąteczną<br>
                        Kliknij poniżej aby ją zobaczyć</p>
                    </td>
                </tr>
                <tr>
                    <td align="center" width="271" style="padding: 15px 0; height: 50px;">
                        <a href="/' . $recipient['token'] . '" style="width: 271px; display: block; height: 50px;"><img style="display: block;" align="center" src="http://prp.dev.plej.pl/mailing/open-pl.jpg" alt="" width="271" height="50"></a>
                    </td>
                </tr>
                <tr>
                    <td align="center" valign="top" style="margin: 0; padding: 0;">
                        <img style="display: block;" src="http://prp.dev.plej.pl/mailing/mailing_header_bottom.gif" alt="" width="600" height="210">
                    </td>
                </tr>


            </table>
        </td>
    </tr>
</table>';
            $mail = new PHPMailer();
            $mail->isSMTP();
            $mail->Host = 'smtp.gmail.com';
            // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;
            // Enable SMTP authentication
            $mail->Username = 'jaroslaw.frydrych@plej.pl';
            // SMTP username
            $mail->Password = 'PaulinA2121';
            // SMTP password
            $mail->SMTPSecure = 'tls';
            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587;
            // TCP port to connect to
            $mail->CharSet = 'UTF-8';
            $mail->setFrom('jaroslaw.frydrych@plej.pl', 'Mailer');
            $mail->addReplyTo('jaroslaw.frydrych@plej.pl', 'Information');
            $mail->isHTML(true);
            $mail->Subject = 'Hej, ' . $recipient['fullName'] . ' mamy życzenia dla Ciebie';
            $mail->Body = $body;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
            $mail->addAddress($recipient['email'], $recipient['fullName']);
            if (!$mail->send()) {
                return false;
            } else {
                $app->db->table('recipients')->where('token', $recipient['token'])->update(array('sendEmail' => 1, 'sendDate' => date("Y-m-d H:i:s")));
            }
        }
    } catch (\Exception $e) {
        throw new Exception("Nie udało się wysłać wiadomości :( " . $mail->ErrorInfo);
    }
    return true;
}
Example #8
0
 /**
  * Set the From and FromName properties.
  *
  * @param   string   $address  The sender email address
  * @param   string   $name     The sender name
  * @param   boolean  $auto     Whether to also set the Sender address, defaults to true
  *
  * @return  boolean
  *
  * @since   11.1
  */
 public function setFrom($address, $name = '', $auto = true)
 {
     try {
         if (parent::setFrom($address, $name, $auto) === false) {
             return false;
         }
     } catch (phpmailerException $e) {
         // The parent method will have already called the logging callback, just log our deprecated error handling message
         JLog::add(__METHOD__ . '() will not catch phpmailerException objects as of 4.0.', JLog::WARNING, 'deprecated');
         return false;
     }
 }