Jump to content

PHP mail headers reply from address with Var


dk4210

Recommended Posts

Hello Guys,

 

I have a strange issue that I am trying to figure out...

 

I have a php mail script that I can't get the correct from email address to display in the email client

 

Here is my code notice the $from2 var

 

If I have this code -  $headers  = "From:'.$from2.'\r\n";

I get a default email address

 

If I add this code -  $headers  = "From:[email protected]\r\n";

it works fine.

 

// multiple recipients
$to = $email;

$from2 = $_SESSION['no_reply'];

//echo "This is the from2" . $from2;
//exit;


// subject
$subject2 = 'You have a new message from ' . $_SESSION['site_name'] .'';


//begin of HTML message
    $message2 = 'You have a new message.<br>'; 
    $message2 .= 'From:  '. $username1; 
    $message2 .= '<br>Message Details'; 
    $message2 .= '<br><a href="'.$site_url .'">Log in to see the message</a>';
    $message2 .= '<br><br><br>';
    
   
   //end of message
    $headers  = "From:'.$from2.'\r\n";
    $headers .= "Content-type: text/html\r\n"; 

  // Mail it
  mail($to, $subject2, $message2, $headers);

 

I did echo out the $form2 to make sure it had a value and it does..

 

Please advise..

 

Thanks, Dan

Hi WebStyles,

 

I tried the following

 

/ multiple recipients
$to = $email;

//$from2 = "someonelse@".$url."";
$from2 = $_SESSION['no_reply'];

//echo "This is the from2" . $from2;
//exit;


// subject
$subject2 = 'You have a new message from ' . $_SESSION['site_name'] .'';


//begin of HTML message
    $message2 = 'You have a new message.<br>'; 
    $message2 .= 'From:  '. $username1; 
    $message2 .= '<br>Message Details'; 
    $message2 .= '<br><a href="'.$site_url .'">Log in to see the message</a>';
    $message2 .= '<br><br><br>';
    
   
   //end of message
    $headers  = "From:".$from2."\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 

  // Mail it
  mail($to, $subject2, $message2, $headers);

 

And it never sent the email at all

 

chintansshah,

 

I tried what told me to do and it just sent the default email address..

 

The strange thing is if I manually add the address in there it works fine but if I try to use a variable it malfunctions in one way or another..

 

Please advise

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.