1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This example shows settings to use when sending via Google's Gmail servers. |
5
|
|
|
* This uses traditional id & password authentication - look at the gmail_xoauth.phps |
6
|
|
|
* example to see how to use XOAUTH2. |
7
|
|
|
* The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
//Import PHPMailer classes into the global namespace |
11
|
|
|
use PHPMailer\PHPMailer\PHPMailer; |
|
|
|
|
12
|
|
|
use PHPMailer\PHPMailer\SMTP; |
|
|
|
|
13
|
|
|
|
14
|
|
|
require 'app/vendor/autoload.php'; |
15
|
|
|
|
16
|
|
|
//Create a new PHPMailer instance |
17
|
|
|
$mail = new PHPMailer(); |
18
|
|
|
|
19
|
|
|
//Tell PHPMailer to use SMTP |
20
|
|
|
$mail->isSMTP(); |
21
|
|
|
|
22
|
|
|
//Enable SMTP debugging |
23
|
|
|
//SMTP::DEBUG_OFF = off (for production use) |
24
|
|
|
//SMTP::DEBUG_CLIENT = client messages |
25
|
|
|
//SMTP::DEBUG_SERVER = client and server messages |
26
|
|
|
$mail->SMTPDebug = SMTP::DEBUG_SERVER; |
27
|
|
|
|
28
|
|
|
//Set the hostname of the mail server |
29
|
|
|
$mail->Host = 'smtp.gmail.com'; |
30
|
|
|
//Use `$mail->Host = gethostbyname('smtp.gmail.com');` |
31
|
|
|
//if your network does not support SMTP over IPv6, |
32
|
|
|
//though this may cause issues with TLS |
33
|
|
|
|
34
|
|
|
//Set the SMTP port number: |
35
|
|
|
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or |
36
|
|
|
// - 587 for SMTP+STARTTLS |
37
|
|
|
$mail->Port = 465; |
38
|
|
|
|
39
|
|
|
//Set the encryption mechanism to use: |
40
|
|
|
// - SMTPS (implicit TLS on port 465) or |
41
|
|
|
// - STARTTLS (explicit TLS on port 587) |
42
|
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; |
43
|
|
|
|
44
|
|
|
//Whether to use SMTP authentication |
45
|
|
|
$mail->SMTPAuth = true; |
46
|
|
|
|
47
|
|
|
//Username to use for SMTP authentication - use full email address for gmail |
48
|
|
|
$mail->Username = ''; |
49
|
|
|
|
50
|
|
|
//Password to use for SMTP authentication |
51
|
|
|
$mail->Password = ''; |
52
|
|
|
|
53
|
|
|
//Set who the message is to be sent from |
54
|
|
|
//Note that with gmail you can only use your account address (same as `Username`) |
55
|
|
|
//or predefined aliases that you have configured within your account. |
56
|
|
|
//Do not use user-submitted addresses in here |
57
|
|
|
$mail->setFrom('', 'SubRocks'); |
58
|
|
|
|
59
|
|
|
//Set an alternative reply-to address |
60
|
|
|
//This is a good place to put user-submitted addresses |
61
|
|
|
$mail->addReplyTo('', 'SubRocks'); |
62
|
|
|
|
63
|
|
|
//Set who the message is to be sent to |
64
|
|
|
$mail->addAddress('', 'user'); |
65
|
|
|
|
66
|
|
|
//Set the subject line |
67
|
|
|
$mail->Subject = 'SubRocks - Confirm E-Mail'; |
68
|
|
|
|
69
|
|
|
//Read an HTML message body from an external file, convert referenced images to embedded, |
70
|
|
|
//convert HTML into a basic plain-text alternative body |
71
|
|
|
$mail->msgHTML(file_get_contents('verification_text.html'), __DIR__); |
72
|
|
|
|
73
|
|
|
//Attach an image file |
74
|
|
|
// $mail->addAttachment('images/phpmailer_mini.png'); |
75
|
|
|
|
76
|
|
|
//send the message, check for errors |
77
|
|
|
if (!$mail->send()) { |
78
|
|
|
echo 'Mailer Error: ' . $mail->ErrorInfo; |
79
|
|
|
} else { |
80
|
|
|
echo 'Message sent!'; |
81
|
|
|
//Section 2: IMAP |
82
|
|
|
//Uncomment these to save your message in the 'Sent Mail' folder. |
83
|
|
|
#if (save_mail($mail)) { |
84
|
|
|
# echo "Message saved!"; |
85
|
|
|
#} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//Section 2: IMAP |
89
|
|
|
//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php |
90
|
|
|
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php |
91
|
|
|
//You can use imap_getmailboxes($imapStream, '/imap/ssl', '*' ) to get a list of available folders or labels, this can |
92
|
|
|
//be useful if you are trying to get this working on a non-Gmail IMAP server. |
93
|
|
|
function save_mail($mail) |
94
|
|
|
{ |
95
|
|
|
//You can change 'Sent Mail' to any other folder or tag |
96
|
|
|
$path = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail'; |
97
|
|
|
|
98
|
|
|
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP |
99
|
|
|
$imapStream = imap_open($path, $mail->Username, $mail->Password); |
100
|
|
|
|
101
|
|
|
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage()); |
102
|
|
|
imap_close($imapStream); |
103
|
|
|
|
104
|
|
|
return $result; |
105
|
|
|
} |
106
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths