Page 1 of 1

Blank screens Sending attachments

Posted: Fri Jun 01, 2007 6:02 pm
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]

Posted: Fri Jun 01, 2007 6:15 pm
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); ?>

I tried it out on an embedded image

Posted: Sat Jun 02, 2007 10:02 am
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.

Posted: Sat Jun 02, 2007 10:38 am
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.

Posted: Sat Jun 02, 2007 11:41 am
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.

Posted: Sat Jun 02, 2007 4:26 pm
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.

Posted: Sat Jun 02, 2007 9:34 pm
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.