Page 1 of 2

Mail() Hotmail Distress!

Posted: Tue Aug 15, 2006 7:26 am
by moejoe
Hey Guys.

Has Anyone figured out how to bypass Hotmail's So Called 'Security'?
It seems you need a Special Type(s) of Header(s) to successfully send the Mail from your PHP script to there INBOX, And Not JunkBox; In My Case; The Email Doesn't Appear;

Can Some1 Check Out My Script; See If it's "Hotmail Material"...

Code: Select all

<?php

$to  = $emails; //To The Person(s) i want to Sent to
						
$boundary = md5(uniqid("Random") );
$headers  = "MIME-Version: 1.0 \r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
					
//Headers - Additional 
	$headers .= "From: $name<$email>\r\n"; //<<- Seems To Be The Problem.
	$headers .= "Reply-To: <$email>\r\n";
	$headers .= "Return-Path: $email\r\n";
	$headers .= "Date: " .date(r)."\r\n";
	$headers .= "X-SID-PRA: MyDomain<info@domain.com>\r\n";

// subject
$subject = 'Dynamic!';

$message  = "\r\n\r\n--" . $boundary . "\r\n"; //Start Mulitpart!
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";

$message .= "My Plain Message, Just Incase Users don't have HTML supported INBOXES";

//HTML PART
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";


// message
$message .= '
<html>
<body>
My <b> Html Message!! </b>

</body></html>
';

mail($to,$subject,$message,$headers);

?>

Well, Simply, This HTML PHP Script Just doesn't Appear in my Hotmail Inbox! It does with my G-MAIL; Yahoo and ISP (optusnet.com.au) email servers.
Only With Hotmail, If i leave the FROM header out and let the server be the 'from' it SOMETIMES returns in my Junk Box.

Any Ideas?

Thanks For Any Help :)

Posted: Tue Aug 15, 2006 10:04 am
by Chris Corbyn
Use a mailing library nd save yourself a lot of hassle ;)

See signature.

You don't need any "special" headers. You just need correctly structured ones. You also need the correct encoding where it applies.

If you're ona shared host you may be being blocked for other reasons such as IP blacklisting. Hotmail seems to have very strong junk mail filters and RBL checking.

EDIT | Your headers are all tapot... why are you specfying multipart/mime without actually implementing multipart?

Posted: Wed Aug 16, 2006 9:11 am
by moejoe
Thanks For The Script.

I Used it, But There is so Much configuration; and I have gone So Far With My Personal Script.

The Script Works 100% with Every Mail Server EXCEPT Hotmail.
Has Anyone Else Had this Problem?

Posted: Wed Aug 16, 2006 9:16 am
by JayBird
moejoe wrote: The Script Works 100% with Every Mail Server EXCEPT Hotmail.
Has Anyone Else Had this Problem?
d11wtq just told you why your script isn't working...re-read his post

Posted: Thu Aug 17, 2006 5:04 am
by moejoe
Hey;

Yer, I see the Problem.
I switched to Swift.

Configuring it is the worst PHP experience I have ever had!

How Do i get it to work in my circumstance?
I can't even get the Basic Email Working from the 'Documents' on the website!!

Please Help.

Posted: Thu Aug 17, 2006 5:05 am
by JayBird
What code have you got up to now!?

Posted: Thu Aug 17, 2006 5:08 am
by moejoe

Code: Select all

<?php

//Load in the components
require('Swift.php');
require('Swift/Connection/SMTP.php');
$swift = new Swift(new Swift_Connection_SMTP('smtp.mydomain.com'));

$swift->send('my@email.com', 'sender@address.com', 'Test', 'Test');

$swift->close();

?>
Doesn't Work!!! :evil:

Posted: Thu Aug 17, 2006 5:09 am
by JayBird
Im guessing you have actually changed smtp.mydomain.com so YOUR mailserver, and changed the email address!?

Posted: Thu Aug 17, 2006 5:11 am
by moejoe
Haha,
Im a Newbie....But Not that new.

Posted: Thu Aug 17, 2006 5:12 am
by JayBird
why not do it exactly as the example in the docs then it will report errors

Code: Select all

require('../../Swift.php');
require('../../Swift/Connection/SMTP.php');

$mailer = new Swift(new Swift_Connection_SMTP('smtp.somedomain.com'));

//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected()) //Optional
{
	//Sends a simple email
	$mailer->send(
		'"Joe Bloggs" <joe@bloggs.com>',
		'"Your name" <you@yourdomain.com>',
		'Some Subject',
		"Hello Joe it's only me!"
	);
	//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>";

Posted: Thu Aug 17, 2006 5:14 am
by moejoe
Ah;
I used my ISP SMTP servers and it worked.
I'll have to check out my domains one.

Still; My Problem is the Same.

The Message does not Arrives at my Hotmail Account...At All.

Posted: Thu Aug 17, 2006 5:15 am
by JayBird
Probably best to wait until d11wtq is online, he's the email Guru

Posted: Thu Aug 17, 2006 5:22 am
by moejoe
OK;

I Got the HTML and Plain Text Multipart Working.

Heres the Code for Review.

Code: Select all

<?php

//Load in the components
require('Swift.php');
require('Swift/Connection/SMTP.php');
$swift = new Swift(new Swift_Connection_SMTP('SMTP.port.com'));

$html_part = '
<b> HTML TEST</b>
';

$plain_part = "
Plain Text
";

$swift->addPart($plain_part);
$swift->addPart($html_part, 'text/html');

if($swift->send('my@email.com', 'sender@address.com', 'The subject')) {
	echo 'Sent';
}
$swift->close();

?>

Posted: Thu Aug 17, 2006 10:58 am
by Chris Corbyn
Yeah that code is right ;) It's perfectly fine to check if the send() command works rather than checking isConnectes() before it. isConnected() just helps you identify problems earlier.

Is it working ok now? Hotmail issues are often down to spam blockers. You can pretty much rule out the cause being your code (or swift) if you try sending the email from your hosts webmail access (or squirell mail).

Posted: Thu Aug 17, 2006 11:58 am
by s.dot
Hotmail will automatically send your email to the junk box if your domain does not have an SPF record. This is from my own personal experience sending "registration emails". I don't know if they're considered junk or not, but hotmail seems to be the only one to place it in the junk folder.
Dns Report.com wrote:Your domain does not have an SPF record. This means that spammers can easily send out E-mail that looks like it came from your domain, which can make your domain look bad (if the recipient thinks you really sent it), and can cost you money (when people complain to you, rather than the spammer). You may want to add an SPF record ASAP, as 01 Oct 2004 was the target date for domains to have SPF records in place (Hotmail, for example, started checking SPF records on 01 Oct 2004).