PHP Headers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

PHP Headers

Post by spacebiscuit »

Hi,

I am trying to prepare the headrs for an email to be sent by the mail function. I want the 'from' field to be determined by user input and therefore a variable. So I am trying this with:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$email. "\r\n";

However this does not work, the email does not send.

Any ideas what I am doing wrong?

Thanks in advance....

Rob.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Headers

Post by Benjamin »

Code: Select all

 
function mailer($f, $t, $s, $b) { // from to subject body
    $headers = null;
    $headers .= "Return-Path: $f\r\n";
    if (preg_match("#<.*?>#s", $b)) {
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    }
    $headers .= "From: $f\r\n";
    $headers .= "Reply-To: $f\r\n";
    mail($t, $s, $b, $headers);
}
 
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: PHP Headers

Post by spacebiscuit »

Thanks that worked. I already had it working actually, the meials were going to my bulk flder though!

Regards,

Rob.
ehime
Forum Newbie
Posts: 6
Joined: Mon Feb 16, 2009 3:19 pm

Re: PHP Headers

Post by ehime »

robburne would you mind disclosing your source, I was trying to get the same thing working,
but for whatever reason I'm getting a error. Would be nice to have something to check against.

Thanks mate
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: PHP Headers

Post by spacebiscuit »

Code: Select all

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
        
mail($mailto, $mailsubject, $mailbody, $headers);
Let me know if it stil does not work.

Rob.
Post Reply