Mail() Hotmail Distress!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Mail() Hotmail Distress!

Post 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 :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What code have you got up to now!?
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post 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:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Im guessing you have actually changed smtp.mydomain.com so YOUR mailserver, and changed the email address!?
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post by moejoe »

Haha,
Im a Newbie....But Not that new.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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>";
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Probably best to wait until d11wtq is online, he's the email Guru
moejoe
Forum Newbie
Posts: 10
Joined: Tue Aug 15, 2006 7:23 am

Post 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();

?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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).
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply