PDA

View Full Version : Sending mail with php, missing From.


soidog
05-26-2006, 03:48 AM
Hi,
On my old webhost did this scritp worked, the senders email address showed up in the from field. But with vps it doesn't.

When someone sends me a email with this script,<?php
$error_msg = '<p id="fel_meddelande"><b> Du har inte fyllt i alla obligatoriska fält</b></p>';

$error = false;

$submit = $_POST['submit'];

if(empty($submit))
$form_sent = false;
else
$form_sent = true;

if ($form_sent)
{
$to = 'webmaster@thairecept.com' . ', ';


$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

if(!$name) { $error_msg .= '<p id="fel_meddelande_error"><i>. Du måste skriva ditt namn</i><br /></p>'; $error = true;}
if(!$email) { $error_msg .= '<p id="fel_meddelande_error"><i>. Du måste skriva din e-mail</i><br /></p>'; $error = true;}
if(!$subject) { $error_msg .= '<p id="fel_meddelande_error"><i>. Du måste skriva ett ämne</i><br /></p>'; $error = true;}
if(!$message) { $error_msg .= '<p id="fel_meddelande_error"><i>. Du måste skriva ett meddelande</i><br /></p>'; $error = true;}

if($email) { if(!eregi("^[a-z0-9_].+@[a-z0-9\-]+\.[a-z0-9\-\.]+$", $email)){ $error_msg .= "<p id=\"pprojin\"><i>. Felaktig E-postadress</i></p>"; $error = true; }}

if(!$error)
{
$msg = "Namn: \t $name \n";
$msg .= "E-mail: \t $email \n";
$msg .= "Meddelande: \n $message \n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: php\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-to: $name <$email>\r\n";
$headers .= "Return-path: $name <$email>\r\n";
mail($to, $subject ,stripslashes($msg), $headers, "-f$email");
}
}

if (($form_sent) && (!$error))
{
echo '<p id="about_motion_top">Tack för ditt mail ' . $name .'.</p>';
echo '<p id="about_motion_top">Ditt mail skickades utan problem och vi kommer att svara så fort som möjligt. Normalt tar det ca 12 timmar innan du har ett svar.</p>';

}
else
{
if ($error)
{
echo $error_msg;
}

?>
<form action="?sida=kontakta" method="post" name="contact">
<p id="kontakt_text">Namn:<span style="color: #C53A09;">*</span> <input name="name" type="text" value="<?php echo $name ?>" style="margin-left: 7px; height: 16px; width: 180px; border: 1px solid #000; background-color: #ffffff;color: #000000; font-size: 9px;"></p>

<p id="kontakt_text">E-mail:<span style="color: #C53A09;">*</span> <input name="email" type="text" value="<?php echo $email ?>" style="margin-left: 3px; height: 16px; width: 180px; border: 1px solid #000; background-color: #ffffff;color: #000000; font-size: 9px;"></p>

<p id="kontakt_text">Ämne:<span style="color: #C53A09;">*</span> <input name="subject" type="text" value="<?php echo $subject ?>" style="margin-left: 7px; height: 16px; width: 180px; border: 1px solid #000; background-color: #ffffff;color: #000000; font-size: 9px;"></p>

<p id="kontakt_text">Meddelande<span style="color: #C53A09;">*</span>
<br />
<textarea name="message" cols="30" rows="8" style="margin-left: 0px; height: 100px; border: 1px solid #000; background-color: #ffffff; color: #000000; font-size: 12px; font-family: verdana; width: 250px;"><?php echo $message ?></textarea></p>

<input name="submit" type="submit" value="Skicka" style="height: 17px; width: 60px; border: 1px solid #000; background-color: #ffffff; color: #000000; font-size: 9px;">
<input name="submit" type="reset" value="Rensa" style="margin-left: 10px; height: 17px; width: 60px; border: 1px solid #000; background-color: #ffffff; color: #000000; font-size: 9px;">
</form>

<?
}
?>

The senders from mail doesn't show i the from field only root@host.soidog.net

Here is a email inkluded the headers when I'm sending an email to my self with the script,Return-Path: <myemailaddress@myemailaddress.com>
Delivered-To: 8-webmaster@thairecept.com
Received: (qmail 1328 invoked by uid 48); 24 May 2006 17:52:37 +0200
Date: 24 May 2006 17:52:37 +0200
Message-ID: <20060524155237.1324.qmail@host.soidog.net>
To: webmaster@thairecept.com,
Subject: Testar ämne
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
X-Priority: 1
X-MSMail-Priority: High
X-Mailer: php
From: My name <myemailaddress@myemailaddress.com>
Reply-to: My name <myemailaddress@myemailaddress.com>
X-Spam-Checker-Version: SpamAssassin 3.0.5 (2005-11-28) on host.soidog.net
X-Spam-Level: **
X-Spam-Status: No, score=2.6 required=7.0 tests=HTML_10_20,HTML_MESSAGE,
HTML_MIME_NO_HTML_TAG,HTML_SHORT_LENGTH,MIME_HTML_ ONLY,
MISSING_MIMEOLE,NO_RELAYS,X_MSMAIL_PRIORITY_HIGH,X _PRIORITY_ HIGH
autolearn=no version=3.0.5


Namn: My name
E-mail: myemailaddress@myemailaddress.com
Meddelande:
Testing message

I have tried to change things, search the net but I can't find out what's wrong.

Anyone has an clue whats wrong and how I can solv this.

SoiDog...

soidog
05-26-2006, 05:39 AM
Removed \r from the lines where \r\n appered.

SoiDog...

StingRay
05-26-2006, 01:52 PM
Filter your inputs as well. This script is insecure and could be used by spammers.

soidog
05-26-2006, 02:33 PM
Thanks, I have allready done that.

SoiDog...