Jump to content

How to change "from" using mail()?


Kane250

Recommended Posts

I'm sending mail using mail() through php, but every email I get, comes in as apache@localhost. I have tried changing all the headers so that From: comes from my email address, but this still does not change this in the inbox.

 

Any ideas what I need to do to change this? Should I be using something other than mail() ?

 

Thanks!

Link to comment
Share on other sites

I had a similar problem a while back, and the cure was in the 'header' information of the mail function. Post your code and lets see. I'm going offline soon but I'll check back later of no one else comes up with answer

 

Thanks! Here is what I'm using...

 

<?php

$to =  implode(",", $massmail);
$subject = $_POST['subject'];
$message = stripslashes ($_POST['msgpost']);
$from = 'myemail@gmail.com';

//IF AN EMAIL IS POSTED, INSERS THE HEADERS AND SEND EMAIL WITH HTML ENCODING
print "<p>";
if ($_POST) {
mail($to, $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");
print "<b>E-mail sent!</b>";
}


?>

Link to comment
Share on other sites

You need to use the optional fifth parameter and set it to:

<?php
$ fifth_param = '-f ' . $from;
mail($to, $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1",$fifth_param);
?>

 

Ken

Link to comment
Share on other sites

orry to be so slow getting back to you. When I came across this same problem I fixed it like this.....

 



//Declaring variables getting ready for the function
$to      = $row['email'];
$from    = $row['from_email'];
$subject = 'This is the subject';
$message = "Here is the first line of the message.<br><br> $whatever (put a variable in the second line of the message)<br><br>Thanks.<br><br>Bye Bye";



$headers = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
$headers .= "Content-transfer-encoding: 7bit\n";
$headers .= "From: $from_email\n"; 

//The actual function
mail($to, $subject, $message, $headers);

Link to comment
Share on other sites

Is this your server or a shared host?

 

This is not my server...

 

You need to use the optional fifth parameter and set it to:

<?php
$ fifth_param = '-f ' . $from;
mail($to, $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1",$fifth_param);
?>

 

Ken

 

Nope, this didn't change anything :-/

 

orry to be so slow getting back to you. When I came across this same problem I fixed it like this.....

 

Thanks, but this didn't work either...

Link to comment
Share on other sites

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.