-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejemplo_mailer.php
47 lines (38 loc) · 1.89 KB
/
ejemplo_mailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// 4 = Errores de coneccion
//Le indico a la clase que utilice SMTP
$mail->isSMTP(); // Set mailer to use SMTP
//Se hace una autenticación SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
//Indico el servidor de gmail para SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
//Indico el puerto que utiliza gmail
$mail->Port = 465;
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'Gaia#1234'; // SMTP password
// TCP port to connect to
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Johan User'); // Add a recipient
// $mail->addAddress('[email protected]'); // Name is optional
// $mail->addReplyTo('[email protected]', 'Information');
// $mail->addCC('[email protected]');
// $mail->addBCC('[email protected]');
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>