function enviar() { if ($this->cliente->getAccessToken()) { $service = new Google_Service_Gmail($this->cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = Contants::FROM; $mail->FromName = Contants::ALIAS; $mail->AddAddress($this->destino); $mail->AddReplyTo(Contants::FROM, Contants::ALIAS); $mail->Subject = $this->asunto; $mail->Body = $this->mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); $r = 1; } catch (Exception $e) { print $e->getMessage(); $r = 0; } } else { $r = -1; } return $r; }
static function sendActivationMail2($destinatario, $asuntoMensaje, $contenidoMensaje) { session_start(); $activacion = sha1($destinatario . Constant::SEMILLA); $origen = "*****@*****.**"; $alias = "Jonathan"; $destino = $destinatario; $asunto = $asuntoMensaje; $mensaje = $contenidoMensaje; require_once 'googleMail/Google/autoload.php'; require_once 'googleMail/class.phpmailer.php'; //las últimas versiones también vienen con autoload $cliente = new Google_Client(); $cliente->setApplicationName(Constant::APPLICATIONAME); $cliente->setClientId(Constant::CLIENTID); $cliente->setClientSecret(Constant::SECRETCLIENTID); $cliente->setRedirectUri(Constant::URI); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('../clases/googleMail/token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); echo "correo enviado correctamente"; } catch (Exception $e) { print "Error en el envio del correo " . $e->getMessage; } } else { echo "no conectado con gmail"; } }
/** * S/MIME Signing tests (self-signed). * @requires extension openssl */ public function testSigning() { $this->Mail->Subject .= ': S/MIME signing'; $this->Mail->Body = 'This message is S/MIME signed.'; $this->buildBody(); $dn = ['countryName' => 'UK', 'stateOrProvinceName' => 'Here', 'localityName' => 'There', 'organizationName' => 'PHP', 'organizationalUnitName' => 'PHPMailer', 'commonName' => 'PHPMailer Test', 'emailAddress' => '*****@*****.**']; $keyconfig = ["digest_alg" => "sha256", "private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA]; $password = '******'; $certfile = 'certfile.pem'; $keyfile = 'keyfile.pem'; //Make a new key pair $pk = openssl_pkey_new($keyconfig); //Create a certificate signing request $csr = openssl_csr_new($dn, $pk); //Create a self-signed cert $cert = openssl_csr_sign($csr, null, $pk, 1); //Save the cert openssl_x509_export($cert, $certout); file_put_contents($certfile, $certout); //Save the key openssl_pkey_export($pk, $pkeyout, $password); file_put_contents($keyfile, $pkeyout); $this->Mail->sign($certfile, $keyfile, $password); $this->assertTrue($this->Mail->send(), 'S/MIME signing failed'); $msg = $this->Mail->getSentMIMEMessage(); $this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers'); unlink($certfile); unlink($keyfile); }
function send() { if ($this->cliente->getAccessToken()) { $service = new Google_Service_Gmail($this->cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $this->from ? null : Constant::_MAILFROM; $mail->FromName = $this->alias ? null : Constant::_MAILALIAS; $mail->AddAddress($this->to); $mail->AddReplyTo($this->from ? null : Constant::_MAILFROM, $this->alias ? null : Constant::_MAILALIAS); $mail->Subject = $this->subject; $mail->Body = $this->message; $mail->preSend(); $mail->isHTML(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); $r = 1; } catch (Exception $e) { print $e->getMessage(); $r = 0; } } else { $r = -1; } return $r; }
function sendMail($origen, $alias, $destino, $asunto, $mensaje) { if ($this->client->getAccessToken()) { $service = new Google_Service_Gmail($this->client); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); return 1; } catch (Exception $e) { return 0; } } else { return -1; } }
/** * Test address escaping. */ public function testAddressEscaping() { $this->Mail->Subject .= ': Address escaping'; $this->Mail->clearAddresses(); $this->Mail->addAddress('*****@*****.**', 'Tim "The Book" O\'Reilly'); $this->Mail->Body = 'Test correct escaping of quotes in addresses.'; $this->buildBody(); $this->Mail->preSend(); $b = $this->Mail->getSentMIMEMessage(); $this->assertTrue(strpos($b, 'To: "Tim \\"The Book\\" O\'Reilly" <*****@*****.**>') !== false); }
static function sendMail($destino) { $origen = "*****@*****.**"; $asunto = "Validación"; $sha1 = sha1($destino . Constants::SEMILLA); $mensaje = "Hola. Se ha dado de alta en la base de datos. \n Ya solo queda activar la cuenta pulsando sobre el siguiente enlace:\n https://usuarios-carlosgrgr.c9users.io/phpactivar.php?email={$destino}&sha1={$sha1}"; $cliente = new Google_Client(); $cliente->setApplicationName('ProyectoEnviarCorreoDesdeGmail'); $cliente->setClientId('144315405047-hu44apt2g5q2akupkjalbk66ctmm0irb.apps.googleusercontent.com'); $cliente->setClientSecret('A40mAiwufd0-UvupZDkCMJCE'); $cliente->setRedirectUri('https://gestionusuario-carlosgrgr.c9users.io/oauth/guardar.php'); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('./oauth/token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; //El correo que manda $mail->FromName = $alias; //El nombre con el que llega $mail->AddAddress($destino); //A donde se manda $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; //Asunto $mail->Body = $mensaje; //Mensaje $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $r = $service->users_messages->send('me', $mensaje); echo "se ha enviado"; } catch (Exception $e) { print "Error en el envío de correo" . $e->getMessage(); } } else { echo "no conectado con gmail"; } return $r = $r["labelIds"][0]; }
static function sendMail($destino) { $origen = "*****@*****.**"; $asunto = "WU User"; $destino = $destino; $alias = "Mike"; $sha1 = sha1($destino . Constants::SEMILLA); $mensaje = "Saludos Usuario. Para completar su registro en WU pulse el siguiente enlace:\n https://wusuario-miguelfdez79.c9users.io/wu/phpdardealta.php?email={$destino}&sha1={$sha1}"; $cliente = new Google_Client(); $cliente->setApplicationName('ProyectoEnviarCorreo'); $cliente->setClientId('560186546771-323f2k7vuhfr2uma1gdc3o09gjgtuagr.apps.googleusercontent.com'); $cliente->setClientSecret('dtpKnyCb9cuaDontUMC-wntA'); $cliente->setRedirectUri('https://wusuario-miguelfdez79.c9users.io/oauth/guardar.php'); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('../oauth/token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $r = $service->users_messages->send('me', $mensaje); echo "se ha enviado"; } catch (Exception $e) { print "Error en el envío de correo" . $e->getMessage(); } } else { echo "no conectado con gmail"; } return $r["labelIds"][0]; }
//las últimas versiones también vienen con autoload $cliente = new Google_Client(); $cliente->setApplicationName('ProyectoEnviarCorreo'); $cliente->setClientId('304670743598-f6luuojm498kah8fnuqarr0mmcrg918n.apps.googleusercontent.com'); $cliente->setClientSecret('ep2o5eER7ELsUJvptEEkonTk'); $cliente->setRedirectUri('https://pruebacorreo-juanmanuelolalla.c9users.io/oauth/guardar.php'); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); echo "correo enviado correctamente"; } catch (Exception $e) { echo "Algun error"; print $e->getMessage(); } }
static function sendMailCambioEmail($destinatario) { session_start(); $secreto = sha1($destinatario . Constant::SEMILLA); $origen = "*****@*****.**"; $alias = "David"; $destino = $destinatario; $asunto = "Cambio de email."; $mensaje = "Cambiar el email: https://gestiondeusuarios-izvdavid2015.c9users.io/php/viewemail.php?correo={$destinatario}&secreto={$secreto}"; require_once 'MailGoogle/google/autoload.php'; require_once 'MailGoogle/class.phpmailer.php'; //las últimas versiones también vienen con autoload $cliente = new Google_Client(); $cliente->setApplicationName(Constant::PRO1); $cliente->setClientId(Constant::CID1); $cliente->setClientSecret(Constant::CSE1); $cliente->setRedirectUri(Constant::URI1); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('../clases/MailGoogle/token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); echo "Correo enviado correctamente."; } catch (Exception $e) { print $e->getMessage(); echo "Error en el envio de correo"; } } else { echo "No conectado con Gmail."; } }
/** * @return string */ private function buildMessage(array $from, array $to, $subject, $message, array $attachments = null) { $mail = new \PHPMailer(); $mail->CharSet = "UTF-8"; $mail->Encoding = "base64"; //supply with your header info, body etc... $mail->Subject = "You've got mail!"; $mail->setFrom($from['email'], @$from['name']); $mail->addAddress($to['email'], @$to['name']); foreach ($attachments as $att) { $mail->addAttachment($att['path'], @$att['name']); } $mail->isHTML(true); //Message is MANDATORY! So, I force it to a blank space if is empty. $message = !empty($message) ? $message : ' '; $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = strip_tags($message); //create the MIME Message $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); return $mime; }
/** * Saves a copy of the mail if _data/tmp. * * @param boolean $success * @param PHPMailer $mail * @param array $args */ function pwg_send_mail_test($success, $mail, $args) { global $conf, $user, $lang_info; $dir = PHPWG_ROOT_PATH . $conf['data_location'] . 'tmp'; if (mkgetdir($dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) { $filename = $dir . '/mail.' . stripslashes($user['username']) . '.' . $lang_info['code'] . '-' . date('YmdHis') . ($success ? '' : '.ERROR'); if ($args['content_format'] == 'text/plain') { $filename .= '.txt'; } else { $filename .= '.html'; } $file = fopen($filename, 'w+'); if (!$success) { fwrite($file, "ERROR: " . $mail->ErrorInfo . "\n\n"); } fwrite($file, $mail->getSentMIMEMessage()); fclose($file); } }
private function SendByPHPMailer() { $email = $this->config['email']; $mailer = new \PHPMailer(); $mailer->From = $this->From; $mailer->FromName = $this->FromName; $mailer->Subject = $this->Subject; $mailer->Body = $this->Body; $mailer->CharSet = 'UTF-8'; $mailer->msgHTML($mailer->Body); $mailer->IsHtml(true); $mailer->AddAddress($this->TO); if (empty($this->ReplyTo)) { $senderEmail = Form::getSenderEmail(); $this->ReplyTo = empty($senderEmail) ? $this->From : $senderEmail; $this->ReplyToName = $this->FromName; } $mailer->AddReplyTo($this->ReplyTo, $this->ReplyToName); if (!empty($this->CC)) { $CCs = explode(',', $this->CC); foreach ($CCs as $c) { $mailer->AddCC($c); } } if (!empty($this->BCC)) { $BCCs = explode(',', $this->BCC); foreach ($BCCs as $b) { $mailer->AddBCC($b); } } $attachments = Form::getAttachments(); //$this->addLog($attachments); if (is_array($attachments)) { foreach ($attachments as $f) { $mailer->AddAttachment($f['path'], basename($f['name'])); } } $smtp = $this->config['smtp']; $isSMTP = $this->mailer == 'smtp' && !empty($smtp); if ($isSMTP) { $mailer->IsSMTP(); $mailer->Host = $smtp['host']; $mailer->Username = $smtp['user']; $mailer->Password = $smtp['password']; $mailer->SMTPAuth = !empty($mailer->Password); $mailer->SMTPSecure = $smtp['security']; $mailer->Port = empty($smtp['port']) ? 25 : $smtp['port']; $mailer->SMTPDebug = empty($smtp['debug']) ? 0 : 2; } if ($isSMTP && $mailer->SMTPDebug > 0) { ob_start(); } $this->isSent = $mailer->Send(); if ($isSMTP && $mailer->SMTPDebug > 0) { $debug = ob_get_contents(); ob_end_clean(); $this->addLog($debug); } if (!$sent) { $this->sendError = $mailer->ErrorInfo; } $this->sentMIMEMessage = $mailer->getSentMIMEMessage(); return $this->isSent; }
public function send() { if (isset($_SESSION['client'])) { $util = new Google_Utils(); require_once dirname(__FILE__) . '/../libraries/PHPMailer/class.phpmailer.php'; $mail = new PHPMailer(); $mail->ContentType = 'text/plain'; $mail->CharSet = "UTF-8"; $subject = $_POST['subject']; $msg = $_POST['body']; $from = $_SESSION['user']->email; $fname = $_SESSION['user']->name ? $_SESSION['user']->name : $_SESSION['user']->email; $mail->From = $from; $mail->FromName = $fname; $recipients = split(',', $_POST['mail']); foreach ($recipients as $value) { $mail->AddAddress($value); } $mail->AddReplyTo($from, $fname); $mail->Subject = $subject; $mail->Body = $msg; $validAttachments = array(); foreach ($_FILES['attachments']['name'] as $index => $fileName) { $filePath = $_FILES['attachments']['tmp_name'][$index]; if (is_uploaded_file($filePath)) { $attachment = new stdClass(); $attachment->fileName = $fileName; $attachment->filePath = $filePath; $validAttachments[] = $attachment; } } foreach ($validAttachments as $attachment) { $mail->AddAttachment($attachment->filePath, $attachment->fileName); } $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $message = new Google_Service_Gmail_Message(); $raw = $util::urlSafeB64Encode($mime); $message->setRaw($raw); //Creamos una instancia de nuestro "modelo" $mailsModel = new MailsModel(); $aux = $mailsModel->sendMessage($message); $this->helper->redirect('/mails/getAll/SENT'); } else { $this->helper->redirect(); } }
function metodoregistro($gestor) { $email = Request::post('email'); $clave = Request::post('clave'); $claveR = Request::post('claveR'); $consulta = $gestor->get($email)->getEmail(); if ($consulta != null) { $contenidoParticular = Plantilla::cargarPlantilla("../templates/_mensaje.html"); $datos = array("mensaje" => "Error. Ya existe un artista para ese email", "ruta" => "../index.php?op=0"); $contenidoParticular = Plantilla::sustituirDatos($datos, $contenidoParticular); $pagina = Plantilla::cargarPlantilla("../templates/_plantilla.1.html"); $datos = array("contenidoParticular" => $contenidoParticular); echo Plantilla::sustituirDatos($datos, $pagina); } else { if ($clave === $claveR) { $nombreArtistico = $email; $claveCifrada = sha1($clave . Constant::SEMILLA); $artista = new Artista($email, $claveCifrada, $nombreArtistico, 1, 0); $gestor->insert($artista); $destino = $email; $sha1 = sha1($destino . Constant::SEMILLA); $origen = '*****@*****.**'; $asunto = "Validación"; $mensaje = "Confirme su registro a la galería pulsando el siguiente enlace: " . "https://galeria-mmarjusticia.c9users.io/artista/index.php?op=activar&email={$destino}&sha1={$sha1}"; require_once '../clases/Google/autoload.php'; require_once '../clases/class.phpmailer.php'; //las últimas versiones también vienen con autoload $cliente = new Google_Client(); $cliente->setApplicationName('enviar'); $cliente->setClientId("270220163093-pe1ci6joub5ai7k0dgtlloukg764pclj.apps.googleusercontent.com"); $cliente->setClientSecret('U-cIahmOQjJkR4Iyl-A1oL6-'); $cliente->setRedirectUri('https://galeria-mmarjusticia.c9users.io/oauth/guardar.php'); $cliente->setScopes('https://www.googleapis.com/auth/gmail.compose'); $cliente->setAccessToken(file_get_contents('../oauth/token.conf')); if ($cliente->getAccessToken()) { $service = new Google_Service_Gmail($cliente); try { $mail = new PHPMailer(); $mail->CharSet = "UTF-8"; $mail->From = $origen; $mail->FromName = $alias; $mail->AddAddress($destino); $mail->AddReplyTo($origen, $alias); $mail->Subject = $asunto; $mail->Body = $mensaje; $mail->preSend(); $mime = $mail->getSentMIMEMessage(); $mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); $mensaje = new Google_Service_Gmail_Message(); $mensaje->setRaw($mime); $service->users_messages->send('me', $mensaje); $contenidoParticular = Plantilla::cargarPlantilla("../templates/_mensaje.html"); $datos = array("mensaje" => "Para finalizar el registro,verifique su correo electronico y active su cuenta", "ruta" => "../index.php?op=0"); $contenidoParticular = Plantilla::sustituirDatos($datos, $contenidoParticular); $pagina = Plantilla::cargarPlantilla("../templates/_plantilla.1.html"); $datos = array("contenidoParticular" => $contenidoParticular); echo Plantilla::sustituirDatos($datos, $pagina); } catch (Exception $e) { print $e->getMessage(); } } else { $contenidoParticular = Plantilla::cargarPlantilla("../templates/_mensaje.html"); $datos = array("mensaje" => "Ha ocurrido un error con la conexión, por favor repita el proceso", "ruta" => "../index.php?op=0"); $contenidoParticular = Plantilla::sustituirDatos($datos, $contenidoParticular); $pagina = Plantilla::cargarPlantilla("../templates/_plantilla.1.html"); $datos = array("contenidoParticular" => $contenidoParticular); echo Plantilla::sustituirDatos($datos, $pagina); } } else { $contenidoParticular = Plantilla::cargarPlantilla("../templates/_mensaje.html"); $datos = array("mensaje" => "Error. Las contraseñas no coinciden", "ruta" => "../index.php?op=0"); $contenidoParticular = Plantilla::sustituirDatos($datos, $contenidoParticular); $pagina = Plantilla::cargarPlantilla("../templates/_plantilla.1.html"); $datos = array("contenidoParticular" => $contenidoParticular); echo Plantilla::sustituirDatos($datos, $pagina); } } }