Jump to content

Archived

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

SpeedBird

Add host information to mail()

Recommended Posts

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. 

Share this post


Link to post
Share on other sites
What are you sending as your headers?

You don't need to use an old program, you can use this script:
[code]<?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);
?> [/code]

or this to send html mail:
[code]<?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);
?> [/code]

Joe

Share this post


Link to post
Share on other sites
The headers aren't the problem:

[code=php]
<?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);
}
?>
[/code]

I need to send the host information. It would be something like the [i]fromhost[/i] function in Xpertmailer.

Share this post


Link to post
Share on other sites

×

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.