Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. $headers = "MIME-Version: 1.1".PHP_EOL;
  2. $headers .= "Content-type: text/plain; charset=iso-8859-1".PHP_EOL;
  3. $headers .= "From: Meu Nome <eu@seudominio.com>".PHP_EOL; // remetente no LINUX
  4. $headers .= "Return-Path: eu@seudominio.com".PHP_EOL; // return-path
  5. $envio = mail("destinatario@algum-email.com", "Assunto", "Texto", $headers);
  6.  
  7. composer require phpmailer/phpmailer
  8.  
  9. ./projeto
  10. |---- enviaremail.php
  11. |---- PHPMailer-5.2.14/
  12. |---- PHPMailerAutoload.php
  13. |---- ...
  14.  
  15. <?php
  16. require 'PHPMailer-5.2.14/PHPMailerAutoload.php';
  17.  
  18. $mail = new PHPMailer;
  19.  
  20. //$mail->SMTPDebug = 3; // Pra depurar o código remova o // do começo
  21.  
  22. $mail->isSMTP(); // Define como SMTP
  23. $mail->Host = 'smtp.exemplo.com'; // Endereço do SMTP
  24. $mail->Port = 25; // Porta do SMTP
  25. $mail->SMTPAuth = true; // Autenticação no SMTP
  26. $mail->Username = 'contato@exemplo.com'; // SMTP username
  27. $mail->Password = 'senha'; // SMTP password
  28.  
  29. //$mail->setFrom('from@example.com', 'Mailer'); //comentei esta linha pois o Gmail irá detectar se tentar alterar o "from", mas pode tentar
  30.  
  31. //Adiciona destinatários:
  32.  
  33. $mail->addAddress('joe@example.net', 'Joe User'); // Adiciona destinatário
  34. $mail->addAddress('ellen@example.com'); // Destinatário sem nome
  35.  
  36. $mail->addReplyTo('info@example.com', 'Information');
  37.  
  38. //Manda como cópia
  39. $mail->addCC('cc@example.com');
  40.  
  41. //Manda como cópia oculta
  42. $mail->addBCC('bcc@example.com');
  43.  
  44. //Anexos se precisar
  45. $mail->addAttachment('/var/tmp/file.tar.gz');
  46. $mail->addAttachment('/tmp/image.jpg', 'new.jpg');
  47.  
  48.  
  49. //Habilita HTML
  50. $mail->isHTML(true); // Set email format to HTML
  51.  
  52. $mail->Subject = 'Assunto';
  53. $mail->Body = 'Mensagem <b>teste</b>';
  54. $mail->AltBody = 'Mensagem em texto, alternativa ao HTML';
  55.  
  56. if(!$mail->send()) {
  57. echo 'Mailer Error: ' . $mail->ErrorInfo;
  58. } else {
  59. echo 'Mensagem enviada';
  60. }
  61.  
  62. //Set the hostname of the mail server
  63. $mail->Host = 'smtp.gmail.com';
  64.  
  65. // use
  66. // $mail->Host = gethostbyname('smtp.gmail.com');
  67. // Se a rede não suportar SMTP sobre IPv6
  68.  
  69. $mail->Port = 587;
  70. $mail->SMTPSecure = 'tls';
  71. $mail->SMTPAuth = true;
  72. $mail->Username = "username@gmail.com";
  73. $mail->Password = "yourpassword";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement