Jump to content

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:example@example.com\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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.