xref: /PHP-8.2/ext/standard/tests/mail/bug80706.phpt (revision f62f6a6d)
1--TEST--
2Bug #80706 (Headers after Bcc headers may be ignored)
3--SKIPIF--
4<?php
5if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
6require_once __DIR__.'/mail_windows_skipif.inc';
7?>
8--INI--
9SMTP=localhost
10smtp_port=25
11sendmail_from=from@example.com
12--FILE--
13<?php
14
15require_once __DIR__.'/mail_util.inc';
16$users = MailBox::USERS;
17
18$to = $users[0];
19$from = ini_get('sendmail_from');
20$bcc = $users[2];
21$subject = 'mail_bug80706';
22$message = 'hello';
23$xMailer = 'bug80706_x_mailer';
24$headers = "From: {$from}\r\n"
25    . "Bcc: {$bcc}\r\n"
26    . "X-Mailer: {$xMailer}";
27
28$res = mail($to, $subject, $message, $headers);
29
30if ($res !== true) {
31    die("Unable to send the email.\n");
32}
33
34echo "Email sent.\n";
35
36foreach (['to' => $to, 'bcc' => $bcc] as $recipient => $mailAddress) {
37    $mailBox = MailBox::login($mailAddress);
38    $mail = $mailBox->getMailsBySubject($subject);
39    $mailBox->logout();
40
41    if ($mail->isAsExpected($from, $to, $subject, $message)) {
42        echo "Found the email. {$recipient} received.\n";
43    }
44
45    if ($mail->getHeader('X-Mailer') === $xMailer) {
46        echo "The specified x-Mailer exists.\n\n";
47    }
48}
49?>
50--CLEAN--
51<?php
52require_once __DIR__.'/mail_util.inc';
53$subject = 'mail_bug80706';
54foreach ([MailBox::USERS[0], MailBox::USERS[2]] as $mailAddress) {
55    $mailBox = MailBox::login($mailAddress);
56    $mailBox->deleteMailsBySubject($subject);
57    $mailBox->logout();
58}
59?>
60--EXPECT--
61Email sent.
62Found the email. to received.
63The specified x-Mailer exists.
64
65Found the email. bcc received.
66The specified x-Mailer exists.
67