1
votes

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('[email protected]'));

// TO
$message->setTo(array('[email protected]'));

// 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] => [email protected] )

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.

1
have you bothered checking your SMTP server's logs? Even if PHP is doing everything right, there's MANY other places for email to fail, and the first spot to check after PHP is the smtp server.Marc B
I'd say it isn't a matter of what PHP library you use. I bet that btopenworld.com requires a username and password to send messages through them.Álvaro González
before this i was using pear and trying to use gmail to send emails, i have no idea if i have a smtp server, im so confusedLubblobba

1 Answers

0
votes

[email protected]

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.