Forum Moderators: coopster

Message Too Old, No Replies

email head content help

i have been given a script but cannot figure out the head content.

         

ezyid

12:07 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



hello there, thankyou for reading.
i have setup a script on my server that will allow "anonymous" email sending.
one thing the script does not do is very important to me:
when you recieve emails in the head you send your name and your email address. so when the reciever recieves the email they see your name but when the click on your name your email address is there.
this script just sends your email address.
does anyone know how to modify the "head content" of the send mail part so it looks similar to

"From: $sender_name <$sender_email>\r\n";
"Reply-To: $sender_email <$sender_email>\r\n";

here is the script

<?php

ini_set('display_errors',1);
error_reporting(E_ALL^E_NOTICE);

if($_POST['submit']=='Mail'&&ini_get('magic_quotes_gpc'))
{
$_POST['recipient_e_addr']=stripslashes($_POST['recipient_e_addr']);
$_POST['sender_e_addr']=stripslashes($_POST['sender_e_addr']);
$_POST['subject']=stripslashes($_POST['subject']);
$_POST['x_originating_ip']=stripslashes($_POST['x_originating_ip']);
$_POST['message']=stripslashes($_POST['message']);
}

$user_ip_addr=empty($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php

if($_POST['submit']=='Mail')
{
$illegal=FALSE;

if(strlen($_POST['recipient_e_addr'])>100)
{
$illegal=TRUE;
}

if(strlen($_POST['sender_e_addr'])>100)
{
$illegal=TRUE;
}

if(strlen($_POST['subject'])>100)
{
$illegal=TRUE;
}

if(strlen($_POST['x_originating_ip'])>15)
{
$illegal=TRUE;
}

if(!in_array($_POST['content_type'],array('text/plain','text/html')))
{
$illegal=TRUE;
}

if(!$illegal)
{
$problem=FALSE;

if(!eregi('^[_a-z0-9\-]+(\.[_a-z0-9\-]+)*@[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z]{2,4}$',$_POST['recipient_e_addr']))
{
$problem=TRUE;
$error_array[]='Recipient&#39;s e-mail address';
}

if(!eregi('^[_a-z0-9\-]+(\.[_a-z0-9\-]+)*@[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z]{2,4}$',$_POST['sender_e_addr']))
{
$problem=TRUE;
$error_array[]='Sender&#39;s e-mail address';
}

if(strlen($_POST['subject'])<1)
{
$problem=TRUE;
$error_array[]='Subject';
}

if(!ereg('^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$',$_POST['x_originating_ip']))
{
$problem=TRUE;
$error_array[]='X-Originating-IP';
}

if(strlen($_POST['message'])<1¦¦strlen($_POST['message'])>10000)
{
$problem=TRUE;
$error_array[]='Message';
}

if(!$problem)
{
$head="MIME-Version: 1.0\n".
'Content-Type: text/'.($_POST['content_type']=='text/html'?'html':'plain')."; charset=iso-8859-1\n".
'From: '.$_POST['sender_e_addr']."\n".
'X-Originating-IP: ['.$_POST['x_originating_ip']."]\n".
'X-Originating-Email: ['.$_POST['sender_e_addr']."]\n".
"X-Mailer: GC Mail\n";

mail($_POST['recipient_e_addr'],$_POST['subject'],$_POST['message'],$head);
echo '<p>Message has been successfully sent to '.$_POST['recipient_e_addr'].".</p>\n";
}
else
{
echo '<p>The following field'.(count($error_array)>1?'s are':' is')." empty or invalid.</p>\n".
"<ul>\n";

foreach($error_array as $error_item)
{
echo '<li>'.$error_item."</li>\n";
}

echo "</ul>\n".
"<p>Please verify and try again.</p>\n";
}
}
else
{
echo "<p>An illegal operation was encountered.</p>\n";
}
}

?>
<p>This is a free service, you can use this form as much as you
like.<br>
If you would like to see an example of the Head content please
<a href="head.html">click here</a></p>
<p></p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<p><label for="recipient_e_addr"></label></p>
<p><label for="recipient_e_addr">Recipient&#39;s e-mail address,
for example, user@anything.com:</label><br />
<input name="recipient_e_addr" id="recipient_e_addr" type="text" class="inputbox" value="<?php echo htmlentities($_POST['recipient_e_addr'],ENT_QUOTES);?>" size="20" maxlength="100" />
</p>
<p><label for="sender_e_addr">Sender&#39;s e-mail address, for
example, John@Doe.com:</label><br />
<input name="sender_e_addr" id="sender_e_addr" type="text" class="inputbox" value="<?php echo htmlentities($_POST['sender_e_addr'],ENT_QUOTES);?>" size="20" maxlength="100" />
</p>
<p><label for="subject">Subject, for example, How are you?:</label><br />
<input name="subject" id="subject" type="text" class="inputbox" value="<?php echo htmlentities($_POST['subject'],ENT_QUOTES);?>" size="20" maxlength="100" />
</p>
<p><label for="x_originating_ip">X-Originating-IP, for example,
<?php echo htmlentities((empty($user_ip_addr)?'127.0.0.1':$user_ip_addr),ENT_QUOTES);?>
:</label><br />
<input name="x_originating_ip" id="x_originating_ip" type="text" class="inputbox" value="<?php echo htmlentities($_POST['x_originating_ip'],ENT_QUOTES);?>" size="20" maxlength="15" />
</p>
<p><label for="content_type">Content-Type:</label><br />
<select name="content_type" class="inputbox" id="content_type">
<option<?php echo $_POST['content_type']=='text/plain'?' selected="selected"':'';?>>text/plain</option>
<option<?php echo $_POST['content_type']=='text/html'?' selected="selected"':'';?>>text/html</option>
</select>
</p>
<p><label for="message">Message, for example, Hello (max 10,000
chars):</label><br />
<textarea name="message" id="message" rows="10" class="inputbox" cols="45"><?php echo htmlentities($_POST['message'],ENT_QUOTES);?></textarea>
</p>
<p>
<input type="submit" name="submit" value="Mail" class="button"/>
</p>
</form>

if you have got this far, a big

thankyou.
steve.

eaden

3:35 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



Hi there,
You can see that the header infomation is set here:

$head="MIME-Version: 1.0\n".
'Content-Type: text/'.($_POST['content_type']=='text/html'?'html':'plain')."; charset=iso-8859-1\n".
'From: '.$_POST['sender_e_addr']."\n".
'X-Originating-IP: ['.$_POST['x_originating_ip']."]\n".
'X-Originating-Email: ['.$_POST['sender_e_addr']."]\n".
"X-Mailer: GC Mail\n";

it is stored in the varible $head, then passed to the mail function:


mail($_POST['recipient_e_addr'],$_POST['subject'],$_POST['message'],$head);

There is already a From: line, but it doesn't include the name.

adding

'Reply-To: '.$_POST['sender_e_addr']."\n".

below the From: line will do the reply to stuff.

ezyid

1:50 am on Jan 6, 2005 (gmt 0)

10+ Year Member



hello there and takyou for your help i have added the 'Reply-To: '.$_POST['sender_e_addr']."\n".

but what i really did was add another text input and renamed the varyables to "name" instead of sender_e_addr and by doing this in the head i added
'Reply-To: '.$_POST['sender_e_addr']."\n".
but in the email headers when i test it i recieve funny things like say i chose my name was "robert miles" it owuld print in the head From: robert@example.com, miles@example.com
do you have any idea how to fix this.. or am i asking too much.. im very sorry but learning php for me would just be way too much.. as the have seend many diffrent ways of doing this and i understand php that looks more like
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $sender_name <$sender_email>\r\n";
$mailheaders .= "Reply-To: $sender_email <$sender_email>\r\n";

thankyou anyway.
steve.

[edited by: coopster at 1:03 pm (utc) on Jan. 6, 2005]
[edit reason] generalized email per TOS [webmasterworld.com] [/edit]