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
https://forums.phpfreaks.com/topic/106252-how-to-change-from-using-mail/
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 = '[email protected]';

//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>";
}


?>

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);

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

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.