Question: I have written a basic script to send an email using PHPMailer.

When I run my script locally to send the email to myself it works fine but when I try to run it from the server, I don't get an email. I want to send emails without specifying SMTP in PHPMailer.

The PHPMailer library is in the codebase directory which is in the same directory as the code below. Also the same on the server.

Here is my PHP code:

```
$to     = 'aaqib.farooq@example.co.uk';
$toName = 'Aaqib Farooq'

require_once('codebase/PHPMailer/class.phpmailer.php');

$mail             = new PHPMailer;
$mail->From       = "fromname@example.co.uk";
$mail->FromName   = "Joe Bloggs";
$mail->addAddress($to, $toName);
$mail->isHTML(true);
$mail->Subject    = "Subject Text";
$mail->Body       = "<p>Lorem ipsum blah blah blah. This is my messsage.</p>";
$mail->AltBody    = "This is the plain text version of the email content";

if ( !$mail->send() ){
    echo 'Email not sent';
} else {
    echo 'Email was sent successfully';
}

```

I've already checked stackoverflow for answers but couldn't find what I need. Can anyone help?

Answer: 
The simplest way to do this would be to invert your logic. That is to say, place the click handler on the required elements and within that check the state of the checkbox. Try this:

```js
$(document).on('click', '[id^="element-"]', function(e) {
  if ($('#checkbox1').is(':checked'))
    console.log(this.id);
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<label>
  <input type="checkbox" id="checkbox1" />
  Check me!
</label>

<div>
  <button id="element-foo">Foo</button>
  <button id="element-bar">Bar</button>
</div>
```
I tested it out, and this will work for you

```js
$("input[id^=d]").on("click", function() {
    var id = $(this).prop("id");
    if ($("#c1").is(":checked")) {
        console.log(id);
    }
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Dogs <input id="c1" type="checkbox" />
Cats <input id="d1" type="checkbox" />
Zebras <input id="d2" type="checkbox" />
Rhinos <input id="e1" type="checkbox" />
```