[SOLVED] Sending mail with Swift
Posted: Tue Jun 20, 2006 8:54 am
Hey,
This is my code but it won't send out any emails. What's wrong?
I'm not even getting an error message.
Thanks
This is my code but it won't send out any emails. What's wrong?
Code: Select all
<?php
session_start(); // Alltid överst på sidan
error_reporting(E_STRICT);
// Kolla om inloggad = sessionen satt
if (!isset($_SESSION['sess_user'])){
header("Location: index.php");
exit;
}
?>
<?php include '../meny.php'; ?>
<?php include '../meny_mail.php'; ?>
<?php
include "../conn.php";
require('./david/Swift.php');
require('./david/Swift/Swift_SMTP_Connection.php');
$connection = new Swift_SMTP_Connection('xxxxx');
$swift = new Swift($connection);
#################
# VARIABLAR #
#################
$text = $_POST['meddelande'];
$subject = $_POST['subject'];
$sender = $_POST['sender'];
$user = $_POST['user'];
$datum = $_POST['datum'];
$tid = $_POST['tid'];
$NewReplyTo = $_POST['sender'];
$avser = 'skarpt';
$tabell_arkiv = "test_arkiv";
$tabell_epost = "test_mailadresser";
$message2 = "<a href=\"http://www.nippe.net/test/lindahl/briefings/tabort.php?id=22?databas={$tabell_epost}\">Vill du inte längre få detta nyhetsbrev. Klicka här</a>\r\n";
##################
# /VARIABLAR #
##################
$recipients = array();
$result = mysql_query("select epost from test_mailadresser where aktiv='yes'") or die(mysql_error());
//Make our list
$swift->addPart($text, 'text/html');
while ($row = mysql_fetch_assoc($result)) $recipients[] = array($row['epost']);
if (!$swift->hasFailed())
{
//Pass the array to send()
$swift->send(
$recipients,
'"Johan" <"$sender">',
'$subject',
'$text'
);
echo "Allting funkade fin fint";
//Closes cleanly... works without this but it's not as polite.
$swift->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($swift->errors, 1).". Log: ".print_r($swift->transactions, 1);
print_r($swift->transactions);
$laggTill = "INSERT INTO $tabell_arkiv (subject, meddelande, user, datum, tid, status, mailskick, avser)
VALUES ('$subject', '$text', '$user', '$datum', '$tid', 'Ej utskickat', '$sum', '$avser')";
mysql_query($laggTill) or die("SQL: $laggtill <br>".mysql_error());
?>Thanks