Swiftmailer header

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Swiftmailer header

Post by kkonline »

Code: Select all

<?php
 
require_once "/home/site/public_html/addons/swiftmailer/lib/Swift.php";
require_once "/home/site/public_html/addons/swiftmailer/lib/Swift/Connection/NativeMail.php"; //There are various connections to use
include("/home/site/public_html/here/connect.inc.php"); 
 
$swift =& new Swift(new Swift_Connection_NativeMail());
 Swift_CacheFactory::setClassName("Swift_Cache_Disk");
 
//Then you set up the disk cache to write to a writable folder...
Swift_Cache_Disk::setSavePath("/home/bodheorg/public_html/addons/swiftmailer/tests/tmp");
 
$message =& new Swift_Message("subject here");
 
$message->attach(new Swift_Message_Part("some content
 
footer"));
 
//Use the Swift_File class
$message->attach(new Swift_Message_Attachment(
  new Swift_File("/home/site/public_html/mysite/more/moreissue.pdf"), "newpdf.pdf", "application/pdf"));
 
$sql = "SELECT * FROM members WHERE 1 AND `trusted` = 1 AND `status` = 0 AND (`email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' OR `email` LIKE '%@hotmail.%' OR `email` LIKE '%@rediff%') LIMIT 0,35";
 
$result = mysql_query($sql) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
 
$email=$row['email'];
$recipients =& new Swift_RecipientList();
$recipients->addTo($email);
 
$swift->batchSend($message, $recipients, "email@domain.org");
 
mysql_query("UPDATE members SET status = 1 WHERE email LIKE '".$email."%'");
}
 
echo "Complete";
$swift->disconnect();
?>
How can i optimize the above code so it reaches the inbox; what more headers / mail part should i add to confirm it reaches the inbox; currently only mail w/o attachment reaches inbox and mail with the attachment reaches junk;
how to format the mail header properly
Post Reply