addAttachment() public method

Returns false if the file could not be found or read.
public addAttachment ( string $path, string $name = '', string $encoding = 'base64', string $type = '', string $disposition = 'attachment' ) : boolean
$path string Path to the attachment.
$name string Overrides the attachment name.
$encoding string File encoding (see $Encoding).
$type string File extension (MIME) type.
$disposition string Disposition to use
return boolean
示例#1
1
 function send()
 {
     $registry = Registry::getInstance();
     $site_root_absolute = $registry->get('site_root_absolute');
     $mail = new PHPMailer();
     #        $mail->SMTPDebug = 3;                               // Enable verbose debug output
     $mail->isSMTP();
     // Set mailer to use SMTP
     $mail->Host = 'smtp-relay.gmail.com;smtp.gmail.com';
     // Specify main and backup SMTP servers
     #        $mail->Host = 'smtp.gmail.com';                       // Specify main and backup SMTP servers
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = '******';
     // SMTP username
     $mail->Password = '******';
     // SMTP password
     $mail->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $mail->Port = 587;
     // TCP port to connect to
     $mail->isHTML(true);
     // Set email format to HTML
     $mail->setFrom($this->from);
     $mail->addAddress($this->to);
     // Add a recipient
     #        $mail->addAddress('*****@*****.**');               // Name is optional
     if ($this->reply) {
         $mail->addReplyTo($this->reply);
     }
     #        $mail->addCC('*****@*****.**');
     $mail->addBCC('*****@*****.**');
     $mail->Subject = $this->subject;
     $mail->Body = $this->html;
     $mail->AltBody = $this->text;
     if (is_array($this->attachments)) {
         foreach ($this->attachments as $attach) {
             $mail->addAttachment($site_root_absolute . self::BASE_PATH . $this->id . EmailTemplateAttahchment::PATH . $attach->filename);
         }
     }
     if (is_array($this->images)) {
         foreach ($this->images as $image) {
             $mail->addAttachment($site_root_absolute . self::BASE_PATH . $this->id . EmailTemplateEmbedded::PATH . $image->filename, $image->cid, 'base64', null, 'inline');
         }
     }
     foreach ($this->makeHeaders($this->headers) as $name => $value) {
         $mail->addCustomHeader($name, $value);
     }
     $result = $mail->send();
     if (!$result) {
         $this->errorInfo = $mail->ErrorInfo;
     }
     return $result;
 }
示例#2
0
文件: utils.php 项目: GNURub/daw2
function sendEmail($force, $clients, $subject, $body, $resources = array())
{
    $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->Host = SMTP_HOST;
    $mail->SMTPAuth = true;
    $mail->Username = EMAIL;
    $mail->Password = PASSWORD;
    $mail->SMTPSecure = SMTP_SECURE;
    $mail->Port = SMTP_PORT;
    $mail->setFrom(EMAIL, 'The cat long');
    $mail->isHTML(true);
    $mail->Subject = $subject;
    foreach ($clients as $client) {
        if (EMAIL != $client['email'] && !empty($client['news']) || !!$force) {
            $mail->addAddress($client['email']);
        }
    }
    $mail->Body = $body;
    foreach ($resources as $i) {
        if (!isset($i['absolute'])) {
            $mail->addAttachment(IMGS . $i['path']);
        } else {
            $mail->addAttachment($i['path']);
        }
    }
    $mail->AltBody = $body;
    if ($mail->send()) {
        flash('msg', 'Su email se ha enviado correctamente', 'Notificación');
        return header('location: /');
    }
}
function email_helper($sender, $subject, $message, $attachment1, $attachment2)
{
    //if(isset($_POST['add-device'])){
    //Send Mail
    require 'phpMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    //$mail->SMTPDebug = 3;                              // Enable verbose debug output
    $mail->isSMTP();
    // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';
    // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;
    // Enable SMTP authentication
    $mail->Username = '******';
    // SMTP username
    $mail->Password = '******';
    // SMTP password
    $mail->SMTPSecure = 'ssl';
    // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;
    // TCP port to connect to
    $mail->From = '*****@*****.**';
    $mail->FromName = 'National Dangerous Drug Control Board-Sri Lanka';
    $mail->addAddress($sender);
    // Add a recipient
    $mail->addReplyTo('*****@*****.**', 'Support');
    //$mail->addCC('*****@*****.**');
    //$mail->addBCC('*****@*****.**');
    $mail->isHTML(true);
    // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body = $message;
    $mail->AltBody = 'ffff';
    if (!empty($attachment1)) {
        $mail->addAttachment($attachment1);
    }
    if (!empty($attachment2)) {
        $mail->addAttachment($attachment2);
    }
    if (!$mail->send()) {
        //echo 'Message could not be sent.';
        //echo 'Mailer Error: ' . $mail->ErrorInfo;
        return false;
    } else {
        //echo 'Message has been sent';
        return true;
    }
    //}else{
    //		$msg = "<div class='alert alert-danger' role='alert'>Error Adding Device</div>";
    //}
}
示例#4
0
function sendEmail($addressArray, $subject, $body, $altBody, $theFile = Null, $fileName = Null)
{
    $mail = new PHPMailer();
    $mail->isSMTP();
    // Set mailer to use SMTP
    $mail->Host = $mail->From = '*****@*****.**';
    $mail->FromName = "BK Info";
    foreach ($addressArray as $address) {
        $mail->addAddress($address);
        // Add a recipient
    }
    $mail->WordWrap = 50;
    // Set word wrap to 50 characters
    for ($i = 0; $i < count($theFile); $i++) {
        $mail->addAttachment($theFile[$i], $fileName[$i]);
    }
    $mail->isHTML(true);
    // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = $altBody;
    if (!$mail->send()) {
        $response['success'] = false;
        $response['error'] = $mail->ErrorInfo;
        return $response;
    } else {
        $response['success'] = true;
        return $response;
    }
}
示例#5
0
文件: Mailer.php 项目: acp3/core
 /**
  * Sends the email
  *
  * @return bool
  */
 public function send()
 {
     try {
         $this->configure();
         $this->phpMailer->Subject = $this->generateSubject();
         if (is_array($this->from) === true) {
             $this->phpMailer->setFrom($this->from['email'], $this->from['name']);
         } else {
             $this->phpMailer->setFrom($this->from);
         }
         $this->generateBody();
         // Add attachments to the E-mail
         if (count($this->attachments) > 0) {
             foreach ($this->attachments as $attachment) {
                 if (!empty($attachment) && is_file($attachment)) {
                     $this->phpMailer->addAttachment($attachment);
                 }
             }
         }
         if (!empty($this->recipients)) {
             return $this->bcc === true ? $this->sendBcc() : $this->sendTo();
         }
     } catch (\phpmailerException $e) {
         $this->logger->error('mailer', $e);
     } catch (\Exception $e) {
         $this->logger->error('mailer', $e);
     }
     return false;
 }
 public function EnviarCorreo(CorreosDTO $dto)
 {
     $mail = new PHPMailer();
     $mail->isSMTP();
     //Correo del remitente
     $mail->Host = 'smtp.gmail.com';
     $mail->SMTPAuth = true;
     $mail->Username = $dto->getRemitente();
     $mail->Password = $dto->getContrasena();
     $mail->SMTPSecure = 'tls';
     $mail->Port = 587;
     $mail->CharSet = 'UTF-8';
     $mail->setFrom($dto->getRemitente(), $dto->getNombreRemitente());
     //Correo del destinatario
     $mail->addAddress($dto->getDestinatario());
     $mail->addReplyTo($dto->getRemitente(), $dto->getNombreRemitente());
     $mail->addAttachment($dto->getArchivos());
     //Adjuntar Archivos
     $mail->isHTML(true);
     $mail->Subject = $dto->getAsunto();
     //Cuerpo del correo
     $mail->Body = $dto->getContenido();
     if (!$mail->send()) {
         $mensaje2 = 'No se pudo enviar el correo ' . 'Error: ' . $mail->ErrorInfo;
     } else {
         $mensaje2 = 'True';
     }
     return $mensaje2;
 }
示例#7
0
 public function sendmail()
 {
     //trebalo bi ovako nesto da ide ja sam otvorio ovaj mail nalog i dodelio mu ovaj password
     $mail = new PHPMailer();
     $mail->isSMTP();
     // Set mailer to use SMTP
     $mail->Host = 'smtp.mandrillapp.com';
     // Specify main and backup SMTP servers
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = '******';
     // SMTP username
     $mail->Password = '******';
     // SMTP password
     $mail->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $mail->Port = 587;
     // TCP port to connect to
     $mail->From = $this->from_email;
     $mail->FromName = 'Agencija SHOPKO';
     $mail->addAddress($this->to_email);
     // Add a recipient
     $mail->addReplyTo('*****@*****.**');
     $mail->isHTML(true);
     $mail->Subject = $this->subject_str;
     $mail->Body = $this->setup_message();
     if (null !== $this->attachment) {
         foreach ($this->attachment as $a) {
             $mail->addAttachment($a);
         }
     }
     //slanje
     $mail->send();
     //mail($this->to_email, $this->subject_str, $this->setup_message(), $this->setup_headers());
 }
示例#8
0
 public static function send_email($subject, $message, $attachment_file = '', $send_to_email = '')
 {
     require_once APPPATH . 'third_party/PHPMailer/PHPMailerAutoload.php';
     $ci =& get_instance();
     $ci->config->load('my_email');
     $mail = new PHPMailer();
     $mail->CharSet = 'utf-8';
     $mail->isSMTP();
     $mail->Host = $ci->config->item('smtp_host');
     $mail->Port = $ci->config->item('smtp_port');
     $mail->SMTPAuth = true;
     $mail->SMTPSecure = $ci->config->item('smtp_secure');
     $mail->Username = $ci->config->item('smtp_user');
     $mail->Password = $ci->config->item('smtp_pass');
     $mail->From = $ci->config->item('smtp_user');
     $mail->FromName = $ci->config->item('from_name');
     if (!empty($attachment_file)) {
         $mail->addAttachment($attachment_file);
     }
     $mail->addAddress($send_to_email);
     $mail->Subject = $subject;
     $mail->IsHTML(true);
     $mail->Body = $message;
     $mail->AltBody = "text/html";
     if (!$mail->send()) {
         log_message('error', $mail->ErrorInfo);
         return "false";
     }
     return 'true';
 }
示例#9
0
 /**
  * Прикрепление файлов к письму
  *
  * @param array|string $data
  *
  * @return void
  */
 public function attach($data)
 {
     $data = !is_array($data) ? (array) $data : $data;
     foreach ($data as $file) {
         $this->PHPMailer->addAttachment($file);
     }
 }
示例#10
0
function sendMail($to, $subject, $html, $files = false)
{
    $mail = new PHPMailer();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';
    # ssl / tls
    $mail->Port = '465';
    # 465 / 587
    $mail->Username = MAILUSER;
    $mail->Password = MAILPASS;
    $mail->CharSet = 'UTF-8';
    $mail->From = '*****@*****.**';
    $mail->FromName = 'Lagerkvist.eu';
    $mail->addAddress('*****@*****.**');
    $mail->addAddress($to);
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $html;
    $mail->AltBody = strip_tags($html);
    if (is_array($files) and count($files)) {
        foreach ($files as $path => $name) {
            $mail->addAttachment($path, $name);
        }
    }
    if ($mail->send()) {
        return true;
    } else {
        return $mail->ErrorInfo;
    }
}
示例#11
0
function mailsend($subjects, $emailto, $file1, $body, $fName, $lName)
{
    $mail = new PHPMailer();
    $mail->Host = 'smtp.gmail.com';
    // Specify main and backup SMTP servers
    $mail->isSMTP();
    $mail->SMTPAuth = true;
    // Enable SMTP authentication
    $mail->Username = '******';
    // SMTP username
    $mail->Password = '******';
    // SMTP password
    $mail->SMTPSecure = 'ssl';
    // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;
    // TCP port to connect to
    $mail->From = "*****@*****.**";
    $mail->FromName = "ElectroShop Newsletter";
    $mail->addAddress($emailto);
    //Recipient //Name is optional
    $mail->Subject = $subjects;
    $mail->Body = $body;
    $mail->addReplyTo('*****@*****.**', 'ElectroShop Admin');
    $mail->isHTML(true);
    $file = $file1;
    $mail->addAttachment($file, 'ElectroShop Newsletter');
    if (!$mail->send()) {
        //  echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
    }
}
 /**
  * @Route("/dump_db", name="dump_db")
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function dumpDBAction()
 {
     $path = $this->get('kernel')->getRootDir() . '/../web';
     $backupFile = $path . '/backup/renoart_5_' . date("Y-m-d") . '.sql';
     $mail = new \PHPMailer();
     $mail->setFrom('*****@*****.**', 'RenoArt');
     $mail->addAddress('*****@*****.**');
     //        $mail->addAddress('*****@*****.**');
     $mail->Subject = 'Baza danych z ' . date("Y-m-d");
     $mail->Body = 'Baza danych z ' . date("Y-m-d") . ' jest w załączniku.';
     $mail->addAttachment($backupFile);
     if ($mail->send()) {
         $this->addFlash('notice', 'E-mail z kopią bazy danych został wysłany.');
     }
     //        $response = new Response();
     //        // Set headers
     //        $response->headers->set('Cache-Control', 'private');
     //        $response->headers->set('Content-type', mime_content_type($backupFile));
     //        $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($backupFile) . '";');
     //        $response->headers->set('Content-length', filesize($backupFile));
     //
     //        // Send headers before outputting anything
     //        $response->sendHeaders();
     //
     //        $response->setContent(file_get_contents($backupFile));
     return $this->redirect($this->generateUrl('homepage'));
 }
示例#13
0
 public static function send($to_email, $reply_email, $reply_name, $from_email, $from_name, $subject, $body, $attachments = array())
 {
     if (Configuration::model()->emailer->relay == 'SMTP') {
         $email = new \PHPMailer();
         //$email->SMTPDebug   = 4;
         $email->isSMTP();
         $email->Host = Configuration::model()->emailer->host;
         $email->SMTPAuth = Configuration::model()->emailer->auth;
         $email->Username = Configuration::model()->emailer->username;
         $email->Password = Configuration::model()->emailer->password;
         $email->SMTPSecure = Configuration::model()->emailer->security;
         $email->Port = Configuration::model()->emailer->port;
     }
     $email->addAddress($to_email);
     $email->addReplyTo($reply_email, $reply_name);
     $email->setFrom($from_email, $from_name);
     $email->Subject = $subject;
     $email->Body = $body;
     $email->msgHTML($body);
     $email->AltBody = strip_tags(str_replace('<br>', "\n\r", $body));
     if (is_array($attachments)) {
         foreach ($attachments as $value) {
             $email->addAttachment($value);
         }
     }
     $email->send();
 }
 public function send($to, $subject, $message, $from = NULL, $attachments = NULL)
 {
     if (!$this->enabled) {
         return;
     }
     $isHtml = stripos($message, "<html>") !== FALSE;
     $f = $from != NULL ? $from : $this->env->settings()->setting("mail_notification_from");
     $validRecipients = $this->getValidRecipients($to);
     if (count($validRecipients) === 0) {
         Logging::logDebug("No valid recipient email addresses, no mail sent");
         return;
     }
     if (Logging::isDebug()) {
         Logging::logDebug("Sending mail from [" . $f . "] to [" . Util::array2str($validRecipients) . "]: [" . $message . "]");
     }
     set_include_path("vendor/PHPMailer" . DIRECTORY_SEPARATOR . PATH_SEPARATOR . get_include_path());
     require 'class.phpmailer.php';
     $mailer = new PHPMailer();
     $smtp = $this->env->settings()->setting("mail_smtp");
     if ($smtp != NULL and isset($smtp["host"])) {
         $mailer->isSMTP();
         $mailer->Host = $smtp["host"];
         if (isset($smtp["username"]) and isset($smtp["password"])) {
             $mailer->SMTPAuth = true;
             $mailer->Username = $smtp["username"];
             $mailer->Password = $smtp["password"];
         }
         if (isset($smtp["secure"])) {
             $mailer->SMTPSecure = $smtp["secure"];
         }
     }
     $mailer->From = $f;
     foreach ($validRecipients as $recipient) {
         $mailer->addBCC($recipient["email"], $recipient["name"]);
     }
     if (!$isHtml) {
         $mailer->WordWrap = 50;
     } else {
         $mailer->isHTML(true);
     }
     if ($attachments != NULL) {
         //TODO use stream
         foreach ($attachments as $attachment) {
             $mailer->addAttachment($attachment);
         }
     }
     $mailer->Subject = $subject;
     $mailer->Body = $message;
     try {
         if (!$mailer->send()) {
             Logging::logError('Message could not be sent: ' . $mailer->ErrorInfo);
             return FALSE;
         }
         return TRUE;
     } catch (Exception $e) {
         Logging::logError('Message could not be sent: ' . $e);
         return FALSE;
     }
 }
示例#15
0
 /**
  * 
  * @param array $anexos 
  * @see Email->addAnexo
  */
 public function addAttachments(array $anexos)
 {
     if (!empty($anexos)) {
         foreach ($anexos as $anexo_path) {
             $this->php_mailer->addAttachment($anexo_path);
         }
     }
 }
示例#16
0
function email($user, $subject, $body)
{
    require_once 'phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    $mail->isSMTP();
    // Set mailer to use SMTP
    $mail->Host = 'smtp.mail.yahoo.com';
    // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;
    // Enable SMTP authentication
    $mail->Username = '******';
    // SMTP username
    $mail->Password = '******';
    // SMTP password
    $mail->SMTPSecure = 'tls';
    // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;
    // TCP port to connect to
    $mail->From = '@yahoo.com';
    $mail->FromName = '*****@*****.**';
    $mail->addAddress($user);
    // Add a recipient
    $mail->addAddress('');
    // Name is optional
    $mail->addReplyTo('', '');
    $mail->addCC('');
    $mail->addBCC('');
    $mail->addAttachment('');
    // Add attachments
    $mail->addAttachment('');
    // Optional name
    $mail->isHTML(true);
    // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = $body;
    if (!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        // echo 'Message has been sent';
    }
}
示例#17
0
 public function mail_admin($admin_mail, $usertype, $data)
 {
     require 'PHPMailer-master/PHPMailerAutoload.php';
     $mail = new PHPMailer();
     //$mail->SMTPDebug = 3;                               // Enable verbose debug output
     $mail->isSMTP();
     // Set mailer to use SMTP
     $mail->Host = 'smtp.gmail.com';
     // Specify main and backup SMTP servers
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = '******';
     // SMTP username
     $mail->Password = '******';
     // SMTP password
     $mail->SMTPSecure = 'ssl';
     // Enable TLS encryption, `ssl` also accepted
     $mail->Port = 465;
     // TCP port to connect to
     $mail->setFrom('*****@*****.**', 'SplitNShare Webmaster');
     $mail->addAddress($admin_mail, 'tofiq');
     $mail->addAddress('');
     // Name is optional
     $mail->addReplyTo('', '');
     $mail->addCC('');
     $mail->addBCC('');
     $mail->addAttachment('/var/tmp/file.tar.gz');
     // Add attachments
     $mail->addAttachment('/tmp/image.jpg', 'new.jpg');
     // Optional name
     $mail->isHTML(true);
     // Set email format to HTML
     $mail->Subject = 'User ' . $data . ' added';
     $mail->Body = 'Group member ' . $data . ' registered for group';
     $mail->AltBody = '';
     if (!$mail->send()) {
         echo 'Message could not be sent.';
         echo 'Mailer Error: ' . $mail->ErrorInfo;
     } else {
         echo 'Message has been sent';
     }
 }
示例#18
0
 public function sendMailAction()
 {
     $mail = new \PHPMailer();
     //$mail->SMTPDebug = 3;                               // Enable verbose debug output
     $mail->isSMTP();
     // Set mailer to use SMTP
     $mail->Host = 'smtp1.example.com;smtp2.example.com';
     // Specify main and backup SMTP servers
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = '******';
     // SMTP username
     $mail->Password = '******';
     // SMTP password
     $mail->SMTPSecure = 'tls';
     // Enable TLS encryption, `ssl` also accepted
     $mail->Port = 587;
     // TCP port to connect to
     $mail->setFrom('*****@*****.**', 'Mailer');
     $mail->addAddress('*****@*****.**', 'Joe User');
     // Add a recipient
     $mail->addAddress('*****@*****.**');
     // Name is optional
     $mail->addReplyTo('*****@*****.**', 'Information');
     $mail->addCC('*****@*****.**');
     $mail->addBCC('*****@*****.**');
     $mail->addAttachment('/var/tmp/file.tar.gz');
     // Add attachments
     $mail->addAttachment('/tmp/image.jpg', 'new.jpg');
     // Optional name
     $mail->isHTML(true);
     // Set email format to HTML
     $mail->Subject = 'Here is the subject';
     $mail->Body = 'This is the HTML message body <b>in bold!</b>';
     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
     if (!$mail->send()) {
         echo 'Message could not be sent.';
         echo 'Mailer Error: ' . $mail->ErrorInfo;
     } else {
         echo 'Message has been sent';
     }
 }
示例#19
0
 /**
  * Send an email using PHPMailer
  * @param \Cogeco\Build\Entity\Email\Connector $connector
  * @param \Cogeco\Build\Entity\Email $emailData
  * @throws \Cogeco\Build\Exception
  */
 public static function sendEmail(Connector $connector, Email $emailData)
 {
     $multipleRecipients = count($emailData->to) > 1;
     Task::log("- Sending email {$emailData->subject}\n");
     $mail = new \PHPMailer();
     if ($connector instanceof SmtpConnector) {
         //Tell PHPMailer to use SMTP
         $mail->isSMTP();
         //Enable SMTP debugging
         // 0 = off (for production use)
         // 1 = client messages
         // 2 = client and server messages
         $mail->SMTPDebug = 0;
         //Ask for HTML-friendly debug output
         $mail->Debugoutput = 'html';
         //Set the hostname of the mail server
         $mail->Host = $connector->host;
         //Set the SMTP port number - likely to be 25, 465 or 587
         $mail->Port = $connector->port;
         //Whether to use SMTP authentication
         $mail->SMTPAuth = false;
         // SMTP auth is currently unsupported
         // if ($connector->auth) { }
     } else {
         throw new Exception("EmailTask error: Unsupported email connector");
     }
     // Set the FRom address and name
     $mail->setFrom($emailData->fromAddress, $emailData->fromName);
     //Set a reply-to address, if there is one
     if (!empty($emailData->replyAddress)) {
         $mail->addReplyTo($emailData->replyAddress, $emailData->replyName);
     }
     foreach ($emailData->to as $i => $toAddress) {
         $mail->addAddress($toAddress);
     }
     // Set the subject, HTML body and text
     $mail->Subject = $emailData->subject;
     $mail->msgHTML($emailData->bodyHtml);
     $mail->AltBody = $emailData->bodyText;
     // Set attachments
     if (!empty($emailData->attachments)) {
         foreach ($emailData->attachments as $i => $attachment) {
             $mail->addAttachment($attachment);
         }
     }
     $mail->CharSet = $emailData->encoding;
     // Send the message, check for errors
     if ($mail->send()) {
         Task::log("Email notification" . ($multipleRecipients ? 's' : '') . " sent\n\n");
     } else {
         throw new Exception("Mailer Error: " . $mail->ErrorInfo);
     }
 }
示例#20
0
 public static function sendEmail($from, $to, $subject, $body, array $attachmentAssetIds = array())
 {
     $settings = json_decode(SystemSettings::getSettings(SystemSettings::TYPE_EMAIL_SENDING_SERVER), true);
     //Create a new PHPMailer instance
     $mail = new PHPMailer();
     //Tell PHPMailer to use SMTP
     $mail->isSMTP();
     $mail->isHTML(true);
     //Enable SMTP debugging
     // 0 = off (for production use)
     // 1 = client messages
     // 2 = client and server messages
     $mail->SMTPDebug = isset($settings['SMTPDebug']) ? $settings['SMTPDebug'] : 2;
     //Ask for HTML-friendly debug output
     $mail->Debugoutput = isset($settings['debugOutput']) ? $settings['debugOutput'] : 'html';
     //Set the hostname of the mail server
     $mail->Host = isset($settings['host']) ? $settings['host'] : "";
     //Set the SMTP port number - likely to be 25, 465 or 587
     $mail->Port = isset($settings['port']) ? $settings['port'] : 25;
     //Whether to use SMTP authentication
     $mail->SMTPAuth = isset($settings['SMTPAuth']) ? $settings['SMTPAuth'] : true;
     //Username to use for SMTP authentication
     $mail->Username = isset($settings['username']) ? $settings['username'] : "";
     //Password to use for SMTP authentication
     $mail->Password = isset($settings['password']) ? $settings['password'] : "";
     //Set who the message is to be sent from
     $mail->setFrom($from);
     //Set an alternative reply-to address
     //$mail->addReplyTo('*****@*****.**', 'First Last');
     //Set who the message is to be sent to
     $mail->addAddress($to);
     //Set the subject line
     $mail->Subject = $subject;
     //Read an HTML message body from an external file, convert referenced images to embedded,
     //convert HTML into a basic plain-text alternative body
     //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
     //Replace the plain text body with one created manually
     //$mail->AltBody = 'This is a plain-text message body';
     //html body
     $mail->Body = $body;
     if (count($attachmentAssetIds) > 0) {
         foreach (Asset::getAllByCriteria('assetId in (' . implode(', ', array_fill(0, count($attachmentAssetIds), '?')) . ')', $attachmentAssetIds) as $asset) {
             //Attach an image file
             $mail->addAttachment($asset->getPath(), $asset->getFilename());
         }
     }
     //send the message, check for errors
     if (!$mail->send()) {
         throw new CoreException('SENDING EMAIL ERROR: ' . $mail->ErrorInfo);
     }
     return true;
 }
示例#21
0
function emailalert($img)
{
    date_default_timezone_set('Etc/UTC');
    require '../../phpmailer/PHPMailerAutoload.php';
    //Create a new PHPMailer instance
    $mail = new PHPMailer();
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 2;
    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "******";
    //Password to use for SMTP authentication
    $mail->Password = "******";
    //Set who the message is to be sent from
    $mail->setFrom('*****@*****.**', 'UAV E-mail ');
    //Set an alternative reply-to address
    $mail->addReplyTo('*****@*****.**', 'UAV');
    //Set who the message is to be sent to
    $mail->addAddress('*****@*****.**', 'Raheema');
    $mail->addAddress('*****@*****.**', 'Suganya');
    //Set the subject line
    $mail->Subject = 'UAV e-Mail Alert..';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image fil
    $body = "There is a suspicious action found in the River Bed<br /> Please find the attachment<br />This is a proof taken by the quadcopter<br /> <br /> <br /> <br />Regrads <br /> UAV Control Station ";
    foreach ($img as $imgName) {
        $mail->addAttachment($imgName);
    }
    $mail->MsgHTML($body);
    //send the message, check for errors
    if (!$mail->send()) {
    } else {
        echo "Message sent!";
    }
}
示例#22
0
 /**
  * Simple HTML and attachment test
  */
 public function testAltBodyAttachment()
 {
     $this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
     $this->Mail->AltBody = 'This is the text part of the email.';
     $this->Mail->Subject .= ': AltBody + Attachment';
     $this->Mail->isHTML(true);
     if (!$this->Mail->addAttachment(__FILE__, 'test_attach.txt')) {
         $this->assertTrue(false, $this->Mail->ErrorInfo);
         return;
     }
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
 }
示例#23
0
 public function run()
 {
     $data = $this->job->getData();
     $config = Config::getInstance();
     $mail = new \PHPMailer();
     // Enable SMTP if required:
     if (isset($config->site['smtp_server'])) {
         $mail->IsSMTP();
         $mail->SMTPAuth = true;
         $mail->Host = $config->get('site.smtp_server', null);
         $mail->Username = $config->get('site.smtp_username', null);
         $mail->Password = $config->get('site.smtp_password', null);
     }
     // Is this email a HTML email?
     $mail->IsHTML(false);
     if (!empty($data['html']) && $data['html']) {
         $mail->IsHTML(true);
     }
     $mail->Subject = $data['subject'];
     $mail->CharSet = "UTF-8";
     // Handle recipients and CCs:
     foreach ($data['to'] as $recipient) {
         $mail->addAddress($recipient['email'], $recipient['name']);
     }
     if (isset($data['cc']) && is_array($data['cc'])) {
         foreach ($data['cc'] as $recipient) {
             $mail->addCc($recipient['email'], $recipient['name']);
         }
     }
     // Handle Reply To:
     if (isset($data['reply_to']) && is_array($data['reply_to'])) {
         $mail->addReplyTo($data['reply_to']['email'], $data['reply_to']['name']);
     }
     // Handle From:
     if (isset($config->site['email_from'])) {
         $mail->SetFrom($config->site['email_from'], $config->site['email_from_name']);
     }
     // Handle attachments:
     if (isset($data['attachments']) && is_array($data['attachments'])) {
         foreach ($data['attachments'] as $name => $path) {
             $mail->addAttachment($path, $name);
         }
     }
     $mail->Body = $data['body'];
     if (!$mail->send()) {
         throw new Exception($mail->ErrorInfo);
     }
     return true;
 }
示例#24
0
 public function send($emails, $template, $subject = 'Уведомление', $filepath = null)
 {
     $mail = new \PHPMailer();
     $portal = 'mediafirst.ru';
     $mail->isSMTP();
     //        $mail->SMTPDebug = 2;
     $mail->isHTML(true);
     $mail->CharSet = 'UTF-8';
     $mail->FromName = $portal;
     $mail->Subject = $subject;
     if ($filepath != null) {
         $mail->addAttachment($filepath, 'mediaplan.xls');
     }
     # prod - оптравка через Exim, dev/test - отправка через Gmail
     if ($this->container->getParameter('kernel.environment') == 'prod') {
         $mail->Host = '127.0.0.1';
         $mail->From = '*****@*****.**';
     } else {
         $mail->Host = 'smtp.gmail.com';
         $mail->From = '*****@*****.**';
         $mail->SMTPSecure = 'ssl';
         $mail->Port = 465;
         $mail->SMTPAuth = true;
         $mail->Username = '******';
         $mail->Password = '******';
     }
     # устанавливаем содержимое письма
     $templateParams = array('portal' => $portal);
     if (is_string($template)) {
         $templateName = $template;
     } else {
         $templateName = $template[0];
         $templateParams = array_merge($templateParams, $template[1]);
     }
     if ($templateParams == null) {
         $templateParams = array();
     }
     $mail->Body = $this->templating->render($templateName, $templateParams);
     # устанавливаем получателя(ей) письма
     if (is_string($emails)) {
         $mail->addAddress($emails);
     } else {
         foreach ($emails as $email) {
             $mail->addAddress($email);
         }
     }
     $mail->send();
 }
示例#25
0
 public function sendMailBySMTP($subject = '', $body = '', $to = '', $toName = '', $from = '*****@*****.**', $fromName = 'IMS', $attachmentPaths = array(), $cc = array())
 {
     $mail = new PHPMailer();
     // $mail->SMTPDebug  = 3;                    			// Enables SMTP debug information (for testing)
     $mail->IsSMTP();
     // Set mailer to use SMTP
     $mail->Host = 'smtp.mandrillapp.com';
     // Specify main and backup server
     $mail->SMTPAuth = true;
     // Enable SMTP authentication
     $mail->Username = IMS_SMTP_USERNAME;
     // SMTP username
     $mail->Password = IMS_SMTP_PASSWORD;
     // SMTP password
     $mail->SMTPSecure = 'tls';
     // Enable encryption, 'ssl' also accepted
     $mail->Port = 587;
     // Set the SMTP port
     $mail->From = $from;
     $mail->FromName = $fromName;
     $mail->addAddress($to, $toName);
     // Add a recipient
     // $mail->addAddress('*****@*****.**'); 				// Name is optional
     // $mail->addReplyTo('*****@*****.**', 'Information');
     if (!empty($cc)) {
         foreach ($cc as $email) {
             $mail->addCC($email);
         }
     }
     // $mail->addBCC('*****@*****.**');
     // $mail->addAttachment('/var/tmp/file.tar.gz'); 		// Add attachments
     // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); 	// Optional name
     if (!empty($attachmentPaths)) {
         foreach ($attachmentPaths as $path) {
             $mail->addAttachment($path);
         }
     }
     $mail->isHTML(true);
     // Set email format to HTML
     $mail->Subject = $subject;
     $mail->Body = $body;
     $mail->AltBody = strip_tags($body);
     if (!$mail->Send()) {
         return false;
         // echo 'Mailer Error: ' . $mail->ErrorInfo;
     }
     return true;
 }
示例#26
0
function email($email, $subject, $text, $file)
{
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->From = '*****@*****.**';
    $mail->FromName = 'css 3 button generator';
    $mail->addAddress($email);
    $mail->isHTML(true);
    $mail->addAttachment('tmp/' . $file);
    $mail->Subject = $subject;
    $mail->Body = $text;
    $mail->AltBody = 'HTML и CSS вашей кнопки в прикрипленном файле';
    $res = $mail->send();
    @unlink('tmp/' . $file);
    return $res;
}
示例#27
0
文件: Mailer.php 项目: Quiss/Twiga
 public static function send($emails, $template, $subject, $from, $fileUrl = null, $fileName = null)
 {
     $mail = new \PHPMailer();
     $mail->isHTML(true);
     $mail->CharSet = 'UTF-8';
     $mail->Subject = $subject;
     if (false == env('APP_DEBUG')) {
         $mail->isSMTP();
         $mail->Host = 'mail.twiga.ru';
         $mail->SMTPAuth = true;
         $mail->Username = "******";
         $mail->Password = "******";
         $mail->From = "*****@*****.**";
         $mail->FromName = "Simba";
     } else {
         $mail->isSMTP();
         $mail->Host = 'smtp.mail.ru';
         $mail->SMTPSecure = 'ssl';
         $mail->Port = 465;
         $mail->SMTPAuth = true;
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Артем';
         $mail->Username = '******';
         $mail->Password = '******';
     }
     # устанавливаем содержимое письма
     if (is_string($template)) {
         $templateName = $template;
         $templateParams = [];
     } else {
         $templateName = $template[0];
         $templateParams = $template[1];
     }
     $mail->Body = (string) view($templateName, $templateParams);
     # устанавливаем получателя(ей) письма
     if (is_string($emails)) {
         $mail->addAddress($emails);
     } else {
         foreach ($emails as $email) {
             $mail->addAddress($email);
         }
     }
     if ($fileUrl) {
         $mail->addAttachment($fileUrl, $fileName);
     }
     return $mail->send();
 }
示例#28
0
/**
 * @param $data
 * @param null $file
 * @return bool
 * @throws Exception
 * @throws phpmailerException
 */
function send_message_to_email($data, $file = null)
{
    $mail = new PHPMailer();
    $mail->isSendmail();
    // Указываем отправителя письма
    $mail->setFrom('*****@*****.**', 'Вадим Клычев');
    // Указываем получателя письма
    $mail->addAddress('*****@*****.**', "Вадиму Клычеву");
    // Указываем тему письма
    $mail->Subject = "Отправка письма с сайта WWW-Ka.ru";
    // Устанавливаем текст сообщения
    $mail->msgHTML("Тестовое письмо с вебинара от " . $data['email'] . ' ' . $data['name']);
    if ($file) {
        $mail->addAttachment($file);
    }
    return $mail->send();
}
示例#29
0
文件: Helper.php 项目: haaseit/hcsf
 public static function mailWrapper($to, $subject = '(No subject)', $message = '', $aImagesToEmbed = [], $aFilesToAttach = [])
 {
     $mail = new \PHPMailer();
     $mail->CharSet = 'UTF-8';
     $mail->isMail();
     if (HelperConfig::$core['mail_method'] == 'sendmail') {
         $mail->isSendmail();
     } elseif (HelperConfig::$core['mail_method'] == 'smtp') {
         $mail->isSMTP();
         $mail->Host = HelperConfig::$secrets['mail_smtp_server'];
         $mail->Port = HelperConfig::$secrets['mail_smtp_port'];
         if (HelperConfig::$secrets['mail_smtp_auth'] == true) {
             $mail->SMTPAuth = true;
             $mail->Username = HelperConfig::$secrets['mail_smtp_auth_user'];
             $mail->Password = HelperConfig::$secrets['mail_smtp_auth_pwd'];
             if (HelperConfig::$secrets['mail_smtp_secure']) {
                 $mail->SMTPSecure = 'tls';
                 if (HelperConfig::$secrets['mail_smtp_secure_method'] == 'ssl') {
                     $mail->SMTPSecure = 'ssl';
                 }
             }
         }
     }
     $mail->From = HelperConfig::$core["email_sender"];
     $mail->FromName = HelperConfig::$core["email_sendername"];
     $mail->addAddress($to);
     $mail->isHTML(true);
     $mail->Subject = $subject;
     $mail->Body = $message;
     if (is_array($aImagesToEmbed) && count($aImagesToEmbed)) {
         foreach ($aImagesToEmbed as $sKey => $imgdata) {
             $imginfo = getimagesizefromstring($imgdata['binimg']);
             $mail->addStringEmbeddedImage($imgdata['binimg'], $sKey, $sKey, 'base64', $imginfo['mime']);
         }
     }
     if (is_array($aFilesToAttach) && count($aFilesToAttach)) {
         foreach ($aFilesToAttach as $sValue) {
             if (file_exists($sValue)) {
                 $mail->addAttachment($sValue);
             }
         }
     }
     //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
     return $mail->send();
 }
 /**
  * PDF of a test order is downloaded by this method
  */
 public function downloadpdfAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $id = $this->getRequest()->getParam('id', '');
     $email = $this->getRequest()->getParam('email', 0);
     require_once 'mpdf/mpdf.php';
     $html .= $this->view->action('viewreport', 'patient', 'patient', array('id' => $id));
     $mpdf = new mPDF('+aCJK', 'A4', '', '', 15, 15, 15, 0, 0, 0);
     $mpdf->mirrorMargins = 0;
     $mpdf->setAutoBottomMargin = 'stretch';
     $mpdf->SetDisplayMode('fullwidth');
     $mpdf->WriteHTML($html);
     $fileName = 'PDF_Form' . time() . '.pdf';
     $mpdf->Output('tmp/' . $fileName, $email ? 'F' : 'D');
     if ($email) {
         $patient = patient::getOrderById($id);
         $mail = new PHPMailer();
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Lab';
         $mail->addAddress($patient[0]['email'], '');
         $mail->addAttachment('tmp/' . $fileName);
         $mail->Subject = 'Your Test Report';
         $mail->Body = 'Please find attached report';
         if (!$mail->send()) {
             echo 'Message could not be sent.';
             echo 'Mailer Error: ' . $mail->ErrorInfo;
         } else {
             unlink('tmp/' . $fileName);
             $flashMessenger = $this->_helper->getHelper('FlashMessenger');
             $flashMessenger->addMessage('mail_sent');
             $this->_redirect('/patient/orders');
         }
     }
 }