Blank screens Sending attachments

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
nedrot
Forum Newbie
Posts: 4
Joined: Fri Jun 01, 2007 5:38 pm

Blank screens Sending attachments

Post by nedrot »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've uploaded the php4 version because my server has php4.
Tested it used the "Sending a HTML E-Mail" this worked fine.

So the next step was: 
Sending attachments and Embedding images in HTML E-mails
When I execute these scripts I get blank screens.

This is the simple script working on my server
(replaced x for the real names)

Code: Select all

<?php
 
require_once "admin/swift/lib/Swift.php";
require_once "admin/swift/lib/Swift/Connection/SMTP.php";
 
$swift =& new Swift(new Swift_Connection_SMTP("x.nl", 25));
 
$message =& new Swift_Message("Swift test", "Your message <u>here</u>", "text/html");
 
if ($swift->send($message, "info@x.nl", "info@x.nl"))
{
    echo "Message sent";
}
else
{
    echo "Message failed to send";
}
 
//It's polite to do this when you're finished
$swift->disconnect();

?>

This one I used for the Sending attachments.
(replaced x for the real names)

<?php
 
require_once "admin/swift/lib/Swift.php";
require_once "admin/swift/lib/Swift/Connection/SMTP.php";
 
$swift =& new Swift(new Swift_Connection_SMTP("x.nl", 25));
 
$message =& new Swift_Message("My subject");
$message->attach(new Swift_Message_Part("I have attached a file to this message!"));
 
//Use the Swift_File class
$message->attach(new Swift_Message_Attachment(
  new Swift_File("x.pdf"), "x.pdf", "/pub"));
 
$swift->send($message, "info@x.nl", "info@x.nl");

//recommended to do this
$swift->disconnect();
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What do you get if you turn error reporting on? Blank screens are a sign of fatal errors:

Code: Select all

<?php error_reporting(E_ALL); ini_set("display_errors", true); ?>
nedrot
Forum Newbie
Posts: 4
Joined: Fri Jun 01, 2007 5:38 pm

I tried it out on an embedded image

Post by nedrot »

This worked thought this was only available for php5 like it said in the doc files.
error_reporting(E_ALL); ini_set("display_errors", true);

Figured it out there was a path error thought it was relative but it had to be in the form /home/public_html etc.
Now it worked.

But outlook sees it as junk and and opend it as text.
Set it back to html then it showed the image.

Also in this line a question in this line:
if ($swift->send($message, new Swift_Address("joe@bloggs.com", "Joe"), new Swift_Address("system@domain.tld", "System")))

joe@bloggs.com is this the adres I send the email to.
system@domain.tld and what's this one for ? in outlook I see System as From this is why it sees it as junk I think.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

"System" is the visual name for the address. It produces:

System <system@domain.tld>

Read this for more info on spam evasion:

http://www.swiftmailer.org/wikidocs/v3/tips/spam

There are an incredible number of factors involved in reducing the risk of being blocked as spam. Only the major ones are covered there. For example, I don't cover the fact the all domains should have a postmaster@domain.tld address. If you can meet all the requirements in the above document then your spam risk will be far lower.
nedrot
Forum Newbie
Posts: 4
Joined: Fri Jun 01, 2007 5:38 pm

Post by nedrot »

Still a bit confused lets say :
i want to send a mail to john@mailcity.com
and my domain is planet.com

How would look this line then :

if ($swift->send($message, new Swift_Address("john@mailcity.com", "Joe"), new Swift_Address("info@planet.com", "System")))

So I have to make a multipart email.
nedrot
Forum Newbie
Posts: 4
Joined: Fri Jun 01, 2007 5:38 pm

Post by nedrot »

Sending a multipart email works to let the email client to show the html part with the picture.
When I sent the multipart email without an embedded image the email is not seen as spam.
But when I send the email with a picture, outlook marks it as junk.

Also used an email adress to send from which actually exists.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

HTML emails with images are commonly seen as junk. It's a common spam technique. Usually spamassassin penalizes you depending uponthe ratio of HTML/image to plain-text in your message. Any plain-text part *must* have the same content as the html part too. Sending a plain-text part which says "You need to view this email in HTML" or any other message which looks nothing like the HTML part gets you penalized.

Could you send me a copy of the email ou're trying to send?

I'm not sure what you're asking about the address thing. It simply depends upon whether or not you want your name (or company's name) to show up in hte recipient's mail client, or if you want your email address to show up. "System" sounds like a very dodgy name to send if your website is planet.com. Maybe "Planet Newsletter" or "Planet Customer Support" would be more suitable.
Post Reply