PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
require('swift/Swift.php');
require('swift/Swift/Connection/SMTP.php');
$mailer = new Swift(new Swift_Connection_SMTP('my smtp server', SWIFT_SECURE_PORT, SWIFT_TLS));
//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected()) //Optional
{
//You can call authenticate() anywhere before calling send()
if ($mailer->authenticate('username', 'password'))
{
//Sends a simple email
$mailer->send(
'"Joe Bloggs" <mail@iwanttosendto.com>',
'"Your name" <you@yourdomain.com>',
'Some Subject',
"Hello Joe it's only me!"
);
}
else echo "Didn't authenticate to server";
//Closes cleanly... works without this but it's not as polite.
$mailer->close();
}
else echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
print_r($mailer->transactions);
I get the can't connect error. I tried telnet entering "o", enter, smtpserveraddress 25.
This connected me to my smtp server, so i assume thats ok. Not sure why it's not connecting.
rsmarsha wrote:Yeah it's 1and1, work host. Any idea how i get round this? Or do i just have to use php's mail fuction?
1and1 block outgoing access on most ports for their basic accounts. You need a premium account with them if you want more... you're probably best contacting them yourself. This has been mentioned before about 1and1.
EDIT | Version 2.1.13 includes a connection called "NativeMail" which uses mail() to do the actual sending.