Jump to content

why do emails my site sends to hotmail accounts never get received?


bitt3n

Recommended Posts

A site I manage requires activation of new accounts via a link provided the user via email. Users who register their account with a gmail address, and many other clients, have no problem with this process. However, users who specify a hotmail address never appear to receive messages from my site (although when they email me directly to complain, and I email them back using an email address owned by my site, they receive my reply).

The mail does not end up in the spam folder (confirmed by registering using my own hotmail address). It appears to vanish. I believe this also affects other hosts than hotmail, but I have not confirmed this.

I am using mail() to send the mail.

Where does the mail go? Is there some way to solve this problem? I did find that this problem (including silent mail deletion) is not uncommon:

http://ask.slashdot.org/article.pl?sid=06/06/22/2248253

However I'm not sure what the best way is to fix it.

This is what the header looks like (sent to gmail b/c hotmail eats the mail):

Delivered-To: [email protected]
Received: by 10.65.244.13 with SMTP id w13cs29486qbr;
Thu, 4 Jan 2007 14:34:15 -0800 (PST)
Received: by 10.65.232.19 with SMTP id j19mr14885932qbr.1167950055903;
Thu, 04 Jan 2007 14:34:15 -0800 (PST)
Return-Path: <[email protected]>
Received: from web7.hspheredns.com (web7.hspheredns.com [72.249.34.34])
by mx.google.com with ESMTP id e15si26852774qbe.2007.01.04.14.34.15;
Thu, 04 Jan 2007 14:34:15 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of [email protected] designates 72.249.34.34 as permitted sender)
Received: from web7.hspheredns.com (web7.hspheredns.com [127.0.0.1])
by web7.hspheredns.com (8.13.1/8.13.1) with ESMTP id l04MYEWB020664
for <[email protected]>; Thu, 4 Jan 2007 16:34:14 -0600
Received: (from httpd@localhost)
by web7.hspheredns.com (8.13.1/8.13.1/Submit) id l04MYErL020663;
Thu, 4 Jan 2007 16:34:14 -0600
Date: Thu, 4 Jan 2007 16:34:14 -0600
Message-Id: <[email protected]>
To: [email protected]
Subject: Kinostat: your temporary password.
X-PHP-Script: kinostat.com/forgot_password.php for 24.147.123.54
From: [email protected]
well, in my experience, most of the time you have not put enough detail about yourself. Please show us the script. Email providers check to see if every email which is being sent to a certain address meets a specific criteria, if it doesnt access is denied. things like senderid often help to make verifaction a lot easier. again, showing us the script would help us help you. thanks.

HoTDaWg
sure, here's a script in which I send mail that hotmail never receives. let me know if I can provide any additional info that might help identify the problem. thanks

[code]<?php # Script 13.10 - forgot_password.php
// This page allows a user to reset their password, if forgotten.

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'MMC Kinostat';
$bar_left_title = 'FORGOT PASSWORD';
$bar_right_title = '';
include ('./includes/header.php');

if (isset($_POST['submitted'])) { // Handle the form.

require_once ('../database.php'); // Connect to the database.

if (empty($_POST['email'])) { // Validate the email address.
$uid = FALSE;
echo '<p><font color="red" size="+1">Please enter your email address.</font></p>';
} else {

// Check for the existence of that email address.
$query = "SELECT user_id FROM users WHERE email='" .  escape_data($_POST['email']) . "' LIMIT 1"; // if LIMIT 1 actually does something, something went horribly wrong
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_num_rows($result) == 1) {

// Retrieve the user ID.
list($uid) = mysql_fetch_array ($result, MYSQL_NUM);

} else {
echo '<p><font color="red" size="+1">The submitted email address is not associated with any account.</font></p>';
$uid = FALSE;
}

}

if ($uid) { // If everything's OK.

// Create a new, random password.
$p = substr ( md5(uniqid(rand(),1)), 3, 10);

// Make the query.
$query = "UPDATE users SET password=SHA('$p') WHERE user_id=$uid";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_affected_rows() == 1) { // If it ran OK.

// Send an email.
$body = "Your password to log into Kinostat has been temporarily changed to '$p' (without the quotation marks). Please log in using this password and your username. At that time you may change your password to something more familiar.";
mail ($_POST['email'], 'Kinostat: your temporary password.', $body, 'From: [email protected]');
echo '<p>Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you have logged in with this password, you may change it within your Account settings.</p>';
mysql_close(); // Close the database connection.
include ('./includes/footer.php'); // Include the HTML footer.
exit();

} else { // If it did not run OK.

echo '<p><font color="red" size="+1">Your password could not be changed due to a system error. The system administrator has been notified. We apologize for the inconvenience.</font></p>';

}

} else { // Failed the validation test.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.

?>

<br />
<p>Please enter your email address below to reset your password.</p>
<form action="forgot_password.php" method="post">
<p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<div align="left"><input type="submit" name="submit" value="Reset My Password" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<br />

<?php
include ('./includes/footer.php');
?>[/code]
If I am reading the header info correctly, your sending mail server's IP address is 72.249.34.34 when a script sends through the mail() function (I am guessing this is on Unix and uses sendmail so that the mail server and your web site share a common IP address.) I checked this IP address at www.dnsstuff.com to see if it appears on any spam databases and it appears on three. This could affect how hotmail treats mail sent to it through your script.

When you send mail yourself using a mail client/web interface, this probably goes through your host's main SMTP mail server.
I am guessing the answer would be yes.

I checked your kinostat.com domain at www.dnsreport.com and your receiving mail server (MX record) is - mail2.hspheredns.com. IP=207.210.215.4. If your script sends to this (might require authentication against your mail box) your emails should be sent out. Your hosting company would have more definitive information.
ok, I am trying to send via my SMTP server. I have a question about the PHPMailer SmtpSend() function. When I was using PHPMailer's normal Send() function, I could just use the lines:

[code]
<?php
if(!$mailer->Send())
{
  echo 'There was a problem sending this mail!';
}
else
{
  echo 'Mail sent!';
?>
[/code]
to send the mail and verify it was sent. However PHPMailer's SmtpSend() requires the body and header as arguments. I'm afraid this is a stupid question, but where do I get the header to provide as an argument?

This is the script I am using to send my mail (taken from the PHP Freaks PHPMailer tutorial). I have commented out the regular Send() function and replaced it with the necessary $site['smtp'] variables and the SendSmtp() function:

[code]
<?php

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.inc.php');

// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/phpmailer/mailclass.inc.php');

// instantiate the class
$mailer = new FreakMailer();

//the From address and name are predefined in config.inc.php. to change the default values, use these lines
//$mailer->FromName = 'Your Name';
//$mailer->From = '[email protected]';

//to make the reply-to address different from the from address use the following.
//Note: You can have multiple Reply-To addresses, just duplicate the following line and change the E-Mail address on each line.
//$mailer->AddReplyTo('[email protected]', 'Billing Department');

//To add multiple Recipients, all you have to do is call the AddAddress function once for each E-Mail address you want to send to. Below is an example of three E-Mail addresses.
//Note: There are two arguments in this function. (Recipient Email Address, Recipient Name). The Recipient Name is optional and will not be used if not present.
//Note: It is not recommended to use this method to send out mailing lists! Every recipient that gets the mail will see everyone else's E-Mail address and you may have just violated any kind of trust for your mailing list users!
//$mailer->AddAddress('[email protected]', 'First Person');
//$mailer->AddAddress('[email protected]', 'Second Person');
//$mailer->AddAddress('[email protected]', 'Third Person');

//To carbon copy (CC) recipients you can simply add them to the E-Mail going out by using the following methods. Just like the Adding Multiple Recipients example, you can add multiple CC recipients as well.
//$mailer->AddBCC('[email protected]', 'First Person');

// More than one CC, just keep adding them!
//$mailer->AddCC('[email protected]', 'Second Person');
//$mailer->AddCC('[email protected]', 'Third Person');

//The "invisible" recipients or BCC can be added to an E-Mail going out by using the following methods. Just like the Adding Multiple Recipients example, you can add multiple BCC recipients as well.
//$mailer->AddBCC('[email protected]', 'First Person');

// More than one BCC, just keep adding them!
//$mailer->AddBCC('[email protected]', 'Second Person');
//$mailer->AddBCC('[email protected]', 'Third Person');

//If you want to request a Read Receipt from the person who receives the E-Mail, you can use the following setting:
//$mailer->ConfirmReadingTo = '[email protected]';



// Set the subject
$mailer->Subject = 'This is a test';

// Body
$htmlBody = '<html>
<head>
<title>My HTML Email</title>
</head>
<body>
<img src="http://www.phpfreaks.com/images/phpfreaks_logo.jpg" alt="PHP Freaks" /><br />
<h2>PHP Freaks Rules!</h2>
<p>We invite you to visit <a href="http://www.phpfreaks.com" title="PHP Freaks">PHP Freaks.com</a> for a loving community of PHP Developers who enjoy helping each other learn the language!</p>

<p>Sincerely,<br />
PHP Freaks Staff</p>';

// Body for text only. both bodies will be sent, and the correct one shown.
$textBody = 'this is the text version of the body.';

// the example code originally had $mailer->Body($htmlBody); and the same with $mailer->Body($textBody), but doing it this way doesn't parse for me.. maybe because cartika is using php4.
$mailer->Body = '<html>
<head>
<title>My HTML Email</title>
</head>
<body>
<img src="http://www.phpfreaks.com/images/phpfreaks_logo.jpg" alt="PHP Freaks" /><br />
<h2>PHP Freaks Rules!</h2>
<p>We invite you to visit <a href="http://www.phpfreaks.com" title="PHP Freaks">PHP Freaks.com</a> for a loving community of PHP Developers who enjoy helping each other learn the language!</p>

<p>Sincerely,<br />
PHP Freaks Staff</p>';
$mailer->isHTML(true);
$mailer->AltBody = 'this is the text version of the body.';

//send attachment
//The AddAttachment function has four arguments: AddAttachment(PATH_TO_FILE, FILENAME, ENCODING, HEADER_TYPE). The PATH_TO_FILE is naturally the full path of the file on the webserver. The FILENAME is the name you want the file to be when the recipient receives it. The ENCODING is base64 by default and the HEADER_TYPE is the type of header you want to send. Application/octet-stream is default.
$mailer->AddAttachment('./kinostat_pics/logo.jpg', 'kinostat.jpg');

// Add an address to send to.
$mailer->AddAddress('[email protected]', 'My Name');

/*if(!$mailer->Send())
{
  echo 'There was a problem sending this mail!';
}
else
{
  echo 'Mail sent!';
}*/

$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = 'mail.kinostat.com';
$site['smtp_port'] = null;
$site['smtp_username'] = null;

if(!$mailer->SmtpSend())
{
  echo 'There was a problem sending this mail via SMTP!';
}
else
{
  echo 'Mail sent via SMTP!';
}


//Please make sure that you use the ClearAddress() and ClearAttachments() functions otherwise the users in a Mailing list to which mail is sent via a loop (while $row, etc.) will always be appended to the list [presumably getting mail during successive iterations]. Trust me on this one!
$mailer->ClearAddresses();
$mailer->ClearAttachments();

//Taking Advantage of qmail and Sendmail with PHP Mail
//If you want to bypass the PHP mail() function and use the system's binary mail application to send the E-Mail, you can do so by specifying the type of Mail server and then PHPMailer will execute that Binary which could possibly speed things up quite a bit.

// Setup Mail class and features
//$mailer->IsQmail();
//$mailer->Send();

// Setup Mail class and features
//$mailer->IsSendmail();
//$mailer->Send();
?>
[/code]

The SendSMTP function does send mail (although it the script throws errors on account of the missing arguments). Does that mean it is not necessary to specify a port and username? It seems kind of odd that I could use the server without providing this information.

Also, how do I send different versions of the mail for html and plaintext if there is only one body argument for the function?

This is the FreakMailer function to which that script refers (also taken from the tutorial on this site):

[code]
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/phpmailer/class.phpmailer.php');

class FreakMailer extends PHPMailer
{
    var $priority = 3;
    var $to_name;
    var $to_email;
    var $From = null;
    var $FromName = null;
    var $Sender = null;
 
    function FreakMailer()
    {
      global $site;
     
      // Comes from config.php $site array
     
      if($site['smtp_mode'] == 'enabled')
      {
        $this->Host = $site['smtp_host'];
        $this->Port = $site['smtp_port'];
        if($site['smtp_username'] != '')
        {
        $this->SMTPAuth  = true;
        $this->Username  = $site['smtp_username'];
        $this->Password  =  $site['smtp_password'];
        }
        $this->Mailer = "smtp";
      }
      if(!$this->From)
      {
        $this->From = $site['from_email'];
      }
      if(!$this->FromName)
      {
        $this-> FromName = $site['from_name'];
      }
      if(!$this->Sender)
      {
        $this->Sender = $site['from_email'];
      }
      $this->Priority = $this->priority;
    }
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.