Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $headers = "MIME-Version: 1.1".PHP_EOL;
- $headers .= "Content-type: text/plain; charset=iso-8859-1".PHP_EOL;
- $headers .= "From: Meu Nome <eu@seudominio.com>".PHP_EOL; // remetente no LINUX
- $headers .= "Return-Path: eu@seudominio.com".PHP_EOL; // return-path
- $envio = mail("destinatario@algum-email.com", "Assunto", "Texto", $headers);
- composer require phpmailer/phpmailer
- ./projeto
- |---- enviaremail.php
- |---- PHPMailer-5.2.14/
- |---- PHPMailerAutoload.php
- |---- ...
- <?php
- require 'PHPMailer-5.2.14/PHPMailerAutoload.php';
- $mail = new PHPMailer;
- //$mail->SMTPDebug = 3; // Pra depurar o código remova o // do começo
- $mail->isSMTP(); // Define como SMTP
- $mail->Host = 'smtp.exemplo.com'; // Endereço do SMTP
- $mail->Port = 25; // Porta do SMTP
- $mail->SMTPAuth = true; // Autenticação no SMTP
- $mail->Username = 'contato@exemplo.com'; // SMTP username
- $mail->Password = 'senha'; // SMTP password
- //$mail->setFrom('from@example.com', 'Mailer'); //comentei esta linha pois o Gmail irá detectar se tentar alterar o "from", mas pode tentar
- //Adiciona destinatários:
- $mail->addAddress('joe@example.net', 'Joe User'); // Adiciona destinatário
- $mail->addAddress('ellen@example.com'); // Destinatário sem nome
- $mail->addReplyTo('info@example.com', 'Information');
- //Manda como cópia
- $mail->addCC('cc@example.com');
- //Manda como cópia oculta
- $mail->addBCC('bcc@example.com');
- //Anexos se precisar
- $mail->addAttachment('/var/tmp/file.tar.gz');
- $mail->addAttachment('/tmp/image.jpg', 'new.jpg');
- //Habilita HTML
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Assunto';
- $mail->Body = 'Mensagem <b>teste</b>';
- $mail->AltBody = 'Mensagem em texto, alternativa ao HTML';
- if(!$mail->send()) {
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- } else {
- echo 'Mensagem enviada';
- }
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // Se a rede não suportar SMTP sobre IPv6
- $mail->Port = 587;
- $mail->SMTPSecure = 'tls';
- $mail->SMTPAuth = true;
- $mail->Username = "username@gmail.com";
- $mail->Password = "yourpassword";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement