1

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 = "[email protected]";
            $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?

2
  • 1
    Don't stop the warning. Use a default value instead. Commented Sep 5, 2013 at 10:17
  • Show us the actual function. Probably you can redefine the function as $cc=null, thereby giving it a default value, but we'll not be able to recommend that for sure unless we can see the actual content of the function. Commented Sep 5, 2013 at 10:17

4 Answers 4

7

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("[email protected]", "[email protected]", "subject", "body", "[email protected]");
sendemail("[email protected]", "[email protected]", "subject", "body", "[email protected]", "[email protected]");
Sign up to request clarification or add additional context in comments.

Comments

1

Use this

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

Comments

0

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 .

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.