Email sending php

I have this php code that allows me to send emails, but I can only get it to send emails to my email account on my host server ( If I change the “->setTo” to any other email address I have, the email does not send. (The page goes blank like it should but I never get the email).
Can anyone help me and tell me why this is happening?



require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('', 26)

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('' => 'Adam schroeder'))
  ->setTo(array('', '' => 'Ben'))
  ->setBody('This is what I said yesterday:bla bla bla')

//Send the message
$result = $mailer->send($message);


why not just use mail() ?

It might be a server security setting to stop people hacking your email form to send spam emails.
Have a word with your hosts to confirm.

Because when going through my web server they require SMTP authentication which mai() cannot do. The mail() function can’t authenticate SMTP as far as I understand.