xref: /php-src/ext/standard/tests/mail/bug80751.phpt (revision f62f6a6d)
1--TEST--
2Bug #80751 (Comma in recipient name breaks email delivery)
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
11--FILE--
12<?php
13
14require_once __DIR__.'/mail_util.inc';
15$users = MailBox::USERS;
16
17$to = $users[0];
18$toLine = "\"<bug80751_to_name@example.com>\" <{$to}>";
19
20$from = 'bug80751_from@example.com';
21$fromLine = "\"<bug80751_from_name@example.com>\" <{$from}>";
22
23$cc = $users[1];
24$ccLine = "\"Lastname, Firstname\\\\\" <{$cc}>";
25
26$bcc = $users[2];
27$subject = 'mail_bug80751';
28$message = 'hello';
29
30$headers = "From: {$fromLine}\r\n"
31    . "Cc: {$ccLine}\r\n"
32    . "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$bcc}>\r\n";
33
34$res = mail($toLine, $subject, $message, $headers);
35
36if ($res !== true) {
37    die("Unable to send the email.\n");
38}
39
40echo "Email sent.\n";
41
42foreach (['to' => $to, 'cc' => $cc, 'bcc' => $bcc] as $recipient => $mailAddress) {
43    $mailBox = MailBox::login($mailAddress);
44    $mail = $mailBox->getMailsBySubject($subject);
45    $mailBox->logout();
46
47    if ($mail->isAsExpected($fromLine, $toLine, $subject, $message)) {
48        echo "Found the email. {$recipient} received.\n";
49    }
50
51    if ($mail->getHeader('Return-Path') === $from) {
52        echo "Return-Path is as expected.\n";
53    }
54
55    if ($mail->getHeader('Cc') === $ccLine) {
56        echo "Cc header is as expected.\n\n";
57    }
58}
59?>
60--CLEAN--
61<?php
62require_once __DIR__.'/mail_util.inc';
63$subject = 'mail_bug80751';
64foreach ([MailBox::USERS[0], MailBox::USERS[1], MailBox::USERS[2]] as $mailAddress) {
65    $mailBox = MailBox::login($mailAddress);
66    $mailBox->deleteMailsBySubject($subject);
67    $mailBox->logout();
68}
69?>
70--EXPECT--
71Email sent.
72Found the email. to received.
73Return-Path is as expected.
74Cc header is as expected.
75
76Found the email. cc received.
77Return-Path is as expected.
78Cc header is as expected.
79
80Found the email. bcc received.
81Return-Path is as expected.
82Cc header is as expected.
83