Issues (3)

src/Util.php (1 issue)

1
<?php
2
3
namespace ByJG\Mail;
4
5
use PHPMailer\PHPMailer\PHPMailer;
6
7
class Util
8
{
9
10
    /**
11
     * Get Full Email Name
12
     *
13
     * @param String $name
14
     * @param String $email
15
     * @return String
16
     */
17 20
    public static function getFullEmail($email, $name = "")
18
    {
19 20
        if (!empty($name)) {
20 17
            return "\"" . $name . "\" <" . $email . ">";
21
        } else {
22 20
            return $email;
23
        }
24
    }
25
26 9
    public static function decomposeEmail($fullEmail)
27
    {
28 9
        $pat = "/[\"'](?P<name>[\S\s]*)[\"']\s+<(?P<email>.*)>/";
29 9
        $pat2 = "/<(?P<email>.*)>/";
30
31 9
        $email = $fullEmail;
32 9
        $name = "";
33
34 9
        $parts = null;
35 9
        if (preg_match($pat, $fullEmail, $parts)) {
36 9
            if (array_key_exists("name", $parts)) {
37 9
                $name = $parts["name"];
38
            }
39
40 9
            if (array_key_exists("email", $parts)) {
41 9
                $email = $parts["email"];
42
            }
43 9
            return array("email" => $email, "name" => $name);
44
        }
45
46 7
        if (preg_match($pat2, $fullEmail, $parts)) {
47 1
            if (array_key_exists("email", $parts)) {
48 1
                $email = $parts["email"];
49
            }
50
        }
51
52 7
        return array("email" => $email, "name" => $name);
53
    }
54
55 1
    public static function isValidEmail($email)
56
    {
57 1
        $ret = PHPMailer::validateAddress($email);
58 1
        return (is_numeric($ret) ? $ret == 1 : $ret);
0 ignored issues
show
The condition is_numeric($ret) is always false.
Loading history...
59
    }
60
}
61