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"; } }
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 setting and retrieving message ID. */ public function testMessageID() { $this->Mail->Body = 'Test message ID.'; $id = md5(12345); $this->Mail->MessageID = $id; $this->buildBody(); $this->Mail->preSend(); $lastid = $this->Mail->getLastMessageID(); $this->assertEquals($lastid, $id, 'Custom Message ID mismatch'); }
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]; }
/** * Test setting and retrieving message ID. */ public function testMessageID() { $this->Mail->Body = 'Test message ID.'; $id = md5(12345); $this->Mail->MessageID = $id; $this->buildBody(); $this->Mail->preSend(); $lastid = $this->Mail->getLastMessageID(); $this->assertNotEquals($lastid, $id, 'Invalid Message ID allowed'); $id = '<' . md5(12345) . '@example.com>'; $this->Mail->MessageID = $id; $this->buildBody(); $this->Mail->preSend(); $lastid = $this->Mail->getLastMessageID(); $this->assertEquals($lastid, $id, 'Custom Message ID not used'); $this->Mail->MessageID = ''; $this->buildBody(); $this->Mail->preSend(); $lastid = $this->Mail->getLastMessageID(); $this->assertRegExp('/^<.*@.*>$/', $lastid, 'Invalid default Message ID'); }
//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; }
function preSend() { $this->Encoding = '8bit'; return parent::preSend(); }
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); } } }