Jump to content


Photo

Add host information to mail()


  • Please log in to reply
2 replies to this topic

#1 SpeedBird

SpeedBird
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationBirmingham, England

Posted 26 October 2006 - 12:21 PM

Probably a very newbie question, but is there any way to add host (mail exchanger) information to an outgoing message when using mail()? I have a script that sends an order confirmation to customers, but some email providers and ISP's seem to drop the email. We get inundated with calls from people worried because they never received an order confirmation. I placed a couple of dummy orders to see if I would receive the confirmation. I received it on my company account but I never receive confirmations on my Hotmail account, they don't even make it to the 'junk mail' folder. After a bit of Googling I found out that if you generate emails with a script it should include the host, but I couldn't find a way to add host information in the PHP documentation at php.net and found nothing useful Googling.

Just FYI we are using a fairly old version of X-Cart. Because of modifications we have asked them to do and modifications I have made myself it is going to be quite expensive to upgrade. That said we have another website using the current version of X-Cart and that suffers from the same problem. Because of this I can't (or rather, lack the competence to) integrate a third-party mailer like PHPMailer. What I really need to know is how to include the host in a mail() type function (I already know the hostname and IP address).

I am running PHP 5.1.4 on Windows 2003 Server Web Edition. 
Why is there always so much month left at the end of the money?

#2 php_joe

php_joe
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 26 October 2006 - 03:39 PM

What are you sending as your headers?

You don't need to use an old program, you can use this script:
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

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

or this to send html mail:
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

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

Joe
[url=http://darkswordsguide.com][/url]

#3 SpeedBird

SpeedBird
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationBirmingham, England

Posted 26 October 2006 - 04:00 PM

The headers aren't the problem:

<?php
#
# Send mail abstract function
# $from - from/reply-to address
#
function func_send_mail($to, $subject_template, $body_template, $from, $to_admin, $crypted=false) {
        global $mail_smarty, $sql_tbl;
        global $config, $customer_language, $admin_language;
		global $current_language, $store_language;

		
        if ($to_admin or !$customer_language) {
				if ($current_language)
					$charset = array_pop(func_query_first ("SELECT charset FROM $sql_tbl[countries] WHERE code='$current_language'"));
				else
					$charset = array_pop(func_query_first ("SELECT charset FROM $sql_tbl[countries] WHERE code='".$config["default_admin_language"]."'"));
                $mail_smarty->assign ("lng", $admin_language);
		}
        else {
				$charset = array_pop(func_query_first ("SELECT charset FROM $sql_tbl[countries] WHERE code='$store_language'"));
                $mail_smarty->assign ("lng", $customer_language);
		}
        $mail_smarty->assign ("config", $config);

    $mail_message = $mail_smarty->fetch("$body_template");
    $mail_subject = chop($mail_smarty->fetch("$subject_template"));

        if (($config["PGP"]["enable_pgp"]=="Y") and ($crypted)) {
                $mail_message = func_pgp_encrypt ($mail_message);
        }

        if (stristr(PHP_OS, "win")) {
            $mail_message=str_replace("\n","\r\n",$mail_message);
            $lend = "\r\n";
        }
        else
            $lend = "\n";

		
		$headers = "From: $from".$lend."Reply-to: $from".$lend."X-Mailer: PHP/".phpversion().$lend."MIME-Version: 1.0".$lend;
		
		if ($config["Email"]["html_mail"] == "Y")
			$headers .= "Content-Type: text/html; charset: ".$charset.$lend;
		else
			$headers .= "Content-Type: text/plain; charset: ".$charset.$lend;
		
		if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
			mail($to,$mail_subject,$mail_message,$headers, "-f".$m[1]);
		else
			mail($to,$mail_subject,$mail_message,$headers);
}

function func_send_simple_mail($to, $subject, $body, $from) { 
		global  $config;
		global $current_language;

        if (stristr(PHP_OS, "win")) {
            $body=str_replace("\n","\r\n",$body);
            $lend = "\r\n";
        }
        else
            $lend = "\n";

		if (!empty($current_language))
			$charset = array_pop(func_query_first ("SELECT charset FROM $sql_tbl[countries] WHERE code='$current_language'"));

		if (empty($charset))
			$charset = array_pop(func_query_first ("SELECT charset FROM $sql_tbl[countries] WHERE code='".$config["default_admin_language"]."'"));

		$headers = "From: $from".$lend."Reply-to: $from".$lend."X-Mailer: PHP/".phpversion().$lend;

		if ($config["Email"]["html_mail"] == "Y")
			$headers .= "Content-Type: text/html; charset: ".$charset.$lend;
		else
			$headers .= "Content-Type: text/plain; charset: ".$charset.$lend;

		if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
			mail($to,$subject,$body,$headers, "-f".$m[1]);
		else
			mail($to,$subject,$body,$headers);
}
?>

I need to send the host information. It would be something like the fromhost function in Xpertmailer.
Why is there always so much month left at the end of the money?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users