Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-16-2004, 04:53 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: New Jersey, U.S.
Posts: 293
jdiben RepRank 0
Default PHP Mail

I found the following code that works very well at sending a contact form to an email address (after the form variables are added to the $body variable). Is there a reason that I should not use this? I am currently using matts formmail script, and it works fine but I would like to use the php code below. What are the advantages/disadvantages of using the code below?
Code:
<?php
		$from=$HTTP_POST_VARS['fromName'];
		$to="Webmaster";
		$eMail=$HTTP_POST_VARS['fromEmail'];
		$eMailto="webmaster@mysite.com";
		$subject="Subject goes here";
		$body="Body goes here";
		$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
		mail( '"' . $to . '" <' . $eMailto . '>',
			   $subject, $body,
			   'Return-Path: "' . $from . '" <' . $eMail . ">\n"
			   . 'From: "' . $from . '" <' . $eMail . ">\n"
			   . 'Reply-To: "' . $from . '" <' . $eMail . ">\n"
			   . "X-Mailer: PHP/" . phpversion() . "\n"
			   . "X-From-IP: " . $userip );
?>
Thanks
Joe
Reply With Quote
  #2 (permalink)  
Old 03-21-2004, 06:10 PM
WebProWorld Member
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 83
jamal RepRank 0
Default

Hi jdiben;
the code below will work fine as you mentioned.
In PHP 4.1+ the autoglobal $_POST has been introduced, ($HTTP_POST_VARS is not autoglobal), this is not a big deal right now, but it is recommended that you start using $_POST instead of $HTTP_POST_VARS, they are different variables. See:
http://www.php.net/manual/en/reserve...variables.post

Also I've read somewhere (don't quote me on this) that it is not recommended that you use the "Person's Name <email@example.com>" syntax, but instead use the email address by itself.

Thats all, other than that, this one also returns the php version and mailers IP address as you may know already.

Yours,
Jamal
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0