· 10 years ago · Jan 14, 2016, 01:09 PM
1<?php
2 $from = $_POST['email'];
3 $to = 'meuemail@gmail.com';
4 $subject = $_POST['subject'];
5 $message = $_POST['content'];
6 $headers = 'From: ' . $from . "rn" .
7 'MIME-Version: 1.0' . "rn" .
8 'Content-type: text/html; charset=utf-8';
9 if(mail($to, $subject, $message, $headers))
10 echo "Email sent";
11 else
12 echo "Email sending failed";
13?>
14
15[sendmail]
16smtp_server=smtp.gmail.com
17smtp_port = 587
18default_domain = gmail.com
19
20auth_username=[seuemail]@gmail.com
21auth_password=[suasenha]
22
23[mail function]
24sendmail_path = "C:xamppsendmailsendmail.exe -t"
25SMTP = smtp.gmail.com
26smtp_port = 587
27
28[mail function]
29 sendmail_path = "env -i /usr/sbin/sendmail -t -i"
30 SMTP = smtp.gmail.com
31 smtp_port = 587
32
33<?php
34require 'PHPMailerAutoload.php';
35
36$mail = new PHPMailer;
37
38//$mail->SMTPDebug = 3; // Enable verbose debug output
39
40$mail->isSMTP(); // Set mailer to use SMTP
41$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
42$mail->SMTPAuth = true; // Enable SMTP authentication
43$mail->Username = 'user@example.com'; // SMTP username
44$mail->Password = 'secret'; // SMTP password
45$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
46$mail->Port = 587; // TCP port to connect to
47
48$mail->From = 'from@example.com';
49$mail->FromName = 'Mailer';
50$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
51$mail->addAddress('ellen@example.com'); // Name is optional
52$mail->addReplyTo('info@example.com', 'Information');
53$mail->addCC('cc@example.com');
54$mail->addBCC('bcc@example.com');
55
56$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
57$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
58$mail->isHTML(true); // Set email format to HTML
59
60$mail->Subject = 'Here is the subject';
61$mail->Body = 'This is the HTML message body <b>in bold!</b>';
62$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
63
64if(!$mail->send()) {
65 echo 'Message could not be sent.';
66 echo 'Mailer Error: ' . $mail->ErrorInfo;
67} else {
68 echo 'Message has been sent';
69}
70
71<?php
72
73require("phpmailer/class.phpmailer.php");
74
75
76$mail = new PHPMailer();
77
78$mail->IsSMTP();
79$mail->Host = "ssl://smtp.gmail.com";
80$mail->SMTPAuth = true;
81$mail->SMTPDebug = 0;
82$mail->Port = 465;
83$mail->SMTPSecure = 'tls';
84$mail->Username = 'seuemail@gmail.com';
85$mail->Password = 'sua_senha';
86
87$mail->From = "remetente@mail.com";
88$mail->Sender = "remetente@mail.com";
89$mail->FromName = "Nome do remetente";
90
91$mail->AddAddress('destinatario@mail.com', 'Assunto da mensagem');
92
93//$mail->AddCC('emailpara@copia.com', 'Aqui o nome');
94//$mail->AddBCC('emailcomcopia@oculta', 'Aqui o nome');
95
96$mail->IsHTML(true);
97$mail->CharSet = 'utf-8';
98
99$mail->Subject = "Assunto da Mensagem"; // Assunto da mensagem
100$mail->Body = "Mensagem";
101
102
103// Anexos
104//$mail->AddAttachment("caminho/para/arquivo.pdf", "novo_nome.pdf");
105
106$enviado = $mail->Send();
107
108$mail->ClearAllRecipients();
109$mail->ClearAttachments();
110
111if ($enviado) {
112 echo "E-mail enviado com sucesso!";
113} else {
114 echo "Não foi possÃvel enviar o e-mail.";
115 echo "Informações do erro:" . $mail->ErrorInfo;
116}