Bluehost.com Web Hosting $6.95

mail function and headers

This is a discussion on mail function and headers within the PHP General forums, part of the PHP Programming Forums category; Hi, i'm playing a little bit with the mail function from PHP 5.2.4 and email headers. here ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-12-2008
Alain Roger
 
Posts: n/a
Default mail function and headers

Hi,

i'm playing a little bit with the mail function from PHP 5.2.4 and email
headers.
here is a snippet of my code:

> $headers = 'From: '.$email."< ".$fromname."
> >\r\n".'Reply-To:'.$email."\r\n".'X-Mailer: PHP/' . phpversion();


if (mail($to, $subject, $body,$headers))

{
>

....
>

}
>


where:
$fromname = $name.",".$firstname;

when i run this code, and click on button "reply-to" it works well... i mean
i reply to end user email address ($email).
but i can see in my "FROM-TO" header space

> From: correct_email_address [mailto:name@strange_email@including_partial_domain _name_of_mywebhosting]
>
>
>

"correct_email_address" is referencing to $email without problem.
but the problem comes from "strange_email@including
_partial_domain_name_of_mywebhosting".
in fact, before @ i get a crazy value and why the rest (after @) i get my
webhosting domain name ?

can i turn this strange email address to the same as $email, in order to
have "From : my_email_address@company.xxx [mailto:
my_email_address@company.xxx]" ?

thanks a lot,

Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #2 (permalink)  
Old 03-12-2008
Daniel Brown
 
Posts: n/a
Default Re: [PHP] mail function and headers

On Wed, Mar 12, 2008 at 10:28 AM, Alain Roger <raf.news@gmail.com> wrote:
> Hi,
>
> i'm playing a little bit with the mail function from PHP 5.2.4 and email
> headers.
> here is a snippet of my code:
>
> > $headers = 'From: '.$email."< ".$fromname."
> > >\r\n".'Reply-To:'.$email."\r\n".'X-Mailer: PHP/' . phpversion();


You have the From: header parameters reversed. Try this:

<?
$headers = "From: ".$fromname." <".$email.">\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
/*
....
*/
?>

--
</Dan>

Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>
Reply With Quote
  #3 (permalink)  
Old 03-12-2008
spacemarc
 
Posts: n/a
Default Re: [PHP] mail function and headers

2008/3/12, Daniel Brown <parasane@gmail.com>:
> You have the From: header parameters reversed. Try this:
>
> <?
> $headers = "From: ".$fromname." <".$email.">\r\n";
> $headers .= "Reply-To: ".$email."\r\n";
> $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
> /*
> ....
> */
> ?>


you can add these headers:

$header = "From: $fromname<$email>\n";
$header .= "Reply-To: $email\n";
$header .= "Return-Path: <$email>\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\n";
$header .= "Content-Transfer-encoding: 7bit\n";

Try it.

--
Scripts: http://www.spacemarc.it
Reply With Quote
  #4 (permalink)  
Old 03-12-2008
Alain Roger
 
Posts: n/a
Default Re: [PHP] mail function and headers

ok i will try... what about UTF-8 to ensure unicode ?
my website and especially the form which will send this email, will be
filled in by several nationalities... spanish, english, french, slovak,
german,,...
so isn't it easier to set up utf-8 ?

A.

On Wed, Mar 12, 2008 at 4:11 PM, spacemarc <spacemarc@gmail.com> wrote:

> 2008/3/12, Daniel Brown <parasane@gmail.com>:
> > You have the From: header parameters reversed. Try this:
> >
> > <?
> > $headers = "From: ".$fromname." <".$email.">\r\n";
> > $headers .= "Reply-To: ".$email."\r\n";
> > $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
> > /*
> > ....
> > */
> > ?>

>
> you can add these headers:
>
> $header = "From: $fromname<$email>\n";
> $header .= "Reply-To: $email\n";
> $header .= "Return-Path: <$email>\n";
> $header .= "X-Mailer: PHP/" . phpversion() . "\n";
> $header .= "MIME-Version: 1.0\n";
> $header .= "Content-type: text/plain; charset=iso-8859-1\n";
> $header .= "Content-Transfer-encoding: 7bit\n";
>
> Try it.
>
> --
> Scripts: http://www.spacemarc.it
>




--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #5 (permalink)  
Old 03-12-2008
Alain Roger
 
Posts: n/a
Default Fwd: [PHP] mail function and headers

ok i will try... what about UTF-8 to ensure unicode ?
my website and especially the form which will send this email, will be
filled in by several nationalities... spanish, english, french, slovak,
german,,...
so isn't it easier to set up utf-8 ?

A.


On Wed, Mar 12, 2008 at 4:11 PM, spacemarc <spacemarc@gmail.com> wrote:

> 2008/3/12, Daniel Brown <parasane@gmail.com>:
> > You have the From: header parameters reversed. Try this:
> >
> > <?
> > $headers = "From: ".$fromname." <".$email.">\r\n";
> > $headers .= "Reply-To: ".$email."\r\n";
> > $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
> > /*
> > ....
> > */
> > ?>

>
> you can add these headers:
>
> $header = "From: $fromname<$email>\n";
> $header .= "Reply-To: $email\n";
> $header .= "Return-Path: <$email>\n";
> $header .= "X-Mailer: PHP/" . phpversion() . "\n";
> $header .= "MIME-Version: 1.0\n";
> $header .= "Content-type: text/plain; charset=iso-8859-1\n";
> $header .= "Content-Transfer-encoding: 7bit\n";
>
> Try it.
>
> --
> Scripts: http://www.spacemarc.it
>




--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008



--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #6 (permalink)  
Old 03-12-2008
Alain Roger
 
Posts: n/a
Default Re: [PHP] mail function and headers

ok, so this is what i got and it is still remaining... :-(

Received: from serdev ([127.0.0.1]) by home.com with MailEnable ESMTP; Wed,
> 12 Mar 2008 16:40:18 +0100
> Date: Wed, 12 Mar 2008 16:40:18 +0100
> Subject: subject 3
> To: mymail@tek.com
> From: raf, news <news.raf@gmail.com>
> Reply-To: news.raf@gmail.com
> Return-Path: <webmaster@localhost_home.com>
> X-Mailer: PHP/5.2.4
> MIME-Version: 1.0
> Content-type: text/plain; charset=iso-8859-1
> Content-Transfer-encoding: 7bit
>


as you can see my Return-Path is still pointing on the wrong direction :-(
any other idea ?

A.

On Wed, Mar 12, 2008 at 4:11 PM, spacemarc <spacemarc@gmail.com> wrote:

> 2008/3/12, Daniel Brown <parasane@gmail.com>:
> > You have the From: header parameters reversed. Try this:
> >
> > <?
> > $headers = "From: ".$fromname." <".$email.">\r\n";
> > $headers .= "Reply-To: ".$email."\r\n";
> > $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
> > /*
> > ....
> > */
> > ?>

>
> you can add these headers:
>
> $header = "From: $fromname<$email>\n";
> $header .= "Reply-To: $email\n";
> $header .= "Return-Path: <$email>\n";
> $header .= "X-Mailer: PHP/" . phpversion() . "\n";
> $header .= "MIME-Version: 1.0\n";
> $header .= "Content-type: text/plain; charset=iso-8859-1\n";
> $header .= "Content-Transfer-encoding: 7bit\n";
>
> Try it.
>
> --
> Scripts: http://www.spacemarc.it
>




--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #7 (permalink)  
Old 03-13-2008
Chris
 
Posts: n/a
Default Re: [PHP] mail function and headers


> as you can see my Return-Path is still pointing on the wrong direction :-(
> any other idea ?


return-path is set with the 5th mail() param:

mail($to, $subject, $body, $headers, '-freturn_path_email@address.com');


--
Postgresql & php tutorials
http://www.designmagick.com/
Reply With Quote
  #8 (permalink)  
Old 03-13-2008
Alain Roger
 
Posts: n/a
Default Re: [PHP] mail function and headers

Hi Chris,

interesting thing, but i get the following error message :
*Warning*: mail()
[function.mail<http://test4.rogtek.com/common/function.mail>]:
SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE
MODE. in */test4/common/sendmail.php* on line *119*

how can i solve this by only PHP ? i do not have access to web hosting
server or php.ini.
thx,
Alain.


On Thu, Mar 13, 2008 at 12:57 AM, Chris <dmagick@gmail.com> wrote:

>
> > as you can see my Return-Path is still pointing on the wrong direction

> :-(
> > any other idea ?

>
> return-path is set with the 5th mail() param:
>
> mail($to, $subject, $body, $headers, '-freturn_path_email@address.com');
>
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>




--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
  #9 (permalink)  
Old 03-13-2008
Chris
 
Posts: n/a
Default Re: [PHP] mail function and headers

Alain Roger wrote:
> Hi Chris,
>
> interesting thing, but i get the following error message :
> *Warning*: mail() [function.mail
> <http://test4.rogtek.com/common/function.mail>]: SAFE MODE Restriction
> in effect. The fifth parameter is disabled in SAFE MODE. in
> */test4/common/sendmail.php* on line *119*
>
> how can i solve this by only PHP ? i do not have access to web hosting
> server or php.ini.


1 of 2 options.

1) Find another host with safe-mode disabled
2) Use something like phpmailer to send your emails through an smtp server

--
Postgresql & php tutorials
http://www.designmagick.com/
Reply With Quote
  #10 (permalink)  
Old 03-13-2008
Alain Roger
 
Posts: n/a
Default Re: [PHP] mail function and headers

hiChris,

i've read several forums where this mail() function from PHP initial package
is not so great.
Therefore a lot of people use PHPMailer which is more convenient for that
purpose...especially more flexible.

thanks a lot for your help.

Alain

On Thu, Mar 13, 2008 at 8:35 AM, Chris <dmagick@gmail.com> wrote:

> Alain Roger wrote:
> > Hi Chris,
> >
> > interesting thing, but i get the following error message :
> > *Warning*: mail() [function.mail
> > <http://test4.rogtek.com/common/function.mail>]: SAFE MODE Restriction
> > in effect. The fifth parameter is disabled in SAFE MODE. in
> > */test4/common/sendmail.php* on line *119*
> >
> > how can i solve this by only PHP ? i do not have access to web hosting
> > server or php.ini.

>
> 1 of 2 options.
>
> 1) Find another host with safe-mode disabled
> 2) Use something like phpmailer to send your emails through an smtp server
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>




--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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




All times are GMT +1. The time now is 04:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0