在php发送电子邮件 - swiftmailer

I've been searching for days if not weeks on how to automatically send a simple e-mail in php after a user completes my form. I've tried Pear, PHP mail, Swiftmailer, changed my php.ini, tried different servers and I'm going mad from none of it working. I have not successfully sent one e-mail yet. I've searched endlessly but I still have no idea what to do and why nothing is working. At the moment I'm using Swiftmailer (second time round). I set up a test page with code:

<?php
require_once 'swift/lib/swift_required.php';


// CREATE TRANSPORT CONFIG
$transport = Swift_MailTransport::newInstance();


// CREATE MSG
$message = Swift_Message::newInstance();

// SET PRIORITY TO HIGH
$message->setPriority(2);

// SUBJECT
$message->setSubject('Subject');

// FROM
$message->setFrom(array('example@btopenworld.com'));

// TO
$message->setTo(array('example@googlemail.com'));

// EMAIL BODY
$message->setBody('Test');

// SEND
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);

if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}


?>

Looking at a similar post someone suggested the last part of the code to see errors and my error is:

Failures:Array ( [0] => example@googlemail.com )

No matter what e-mail I change it to (all using e-mails I have, so real e-mails) it doesn't work. If anyone has any help or suggestions it would be hugely appreciated.

example@btopenworld.com

Unless you are using a btopenworld server to send the E-Mail from, this is not going to work. The E-Mails from address needs to be associated with the server you are sending the message from. You can put the BT address into the reply-to header.

Also, SwiftMailer should have a "debug" switch telling you exactly what goes wrong, but I can't find it in the docs right now. Here is a logger plugin for Swiftmailer that should help if all else fails.