PHP函数中缺少参数 - 如何停止警告

I have a PHP function to send emails,

function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto,$cc)
    {
        if(filter_var($email_to, FILTER_VALIDATE_EMAIL))
        {
            require_once "/usr/local/lib/php/Mail.php";

            $from = $email_from;
            $to = $email_to;
            $subject = $email_subject;
            $body = $email_body;

            $host = "mail.domain.co.uk";
            $username = "sending@domain.co.uk";
            $password = "********";

            $headers = array ('From' => $from,
              'To' => $to,
              'Cc' => $cc,
              'Subject' => $subject,
              'Content-type' => 'text/html');
            $smtp = Mail::factory('smtp',
              array ('host' => $host,
             'auth' => true,
             'username' => $username,
             'password' => $password));

             $rec = $to.', '.$cc;

            $mail = $smtp->send($rec, $headers, $body, $cc);
        }
    }

when i call the function, sometimes there is no $cc variable so i get a warning saying that Missing argument 6 for sendemail(),

whats the best way to stop the warning if $cc is not valid?

If you wrote that function, you can make the 6th parameter optional:

function sendemail($email_to, $email_from, $email_subject, $email_body, $email_replyto, $cc = null) {
    if ($cc !== null) {
        // add cc headers, e.g.
        // $headers['Cc'] = $cc;
    }
}

You will then have the option to omit this parameter:

sendemail("to@example.com", "from@example.com", "subject", "body", "replyto@example.com");
sendemail("to@example.com", "from@example.com", "subject", "body", "replyto@example.com", "cc@example.com");

Use this

function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto,$cc = "")

Try this,

function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto,$cc=NULL)

put $cc = NULL. So you will not get warning if there is no $cc .

If you are able to change the send email function:

function sendemail ($email_to, $email_from, $email_subject, $email_body, $email_replyto, $cc=null) { }

Just make sure that the function body itself will not have problem with a null $cc.