Mail "received" header change - php

It has been 2 days now trying to find a solution for this problem.
Recently my local ISP changed their security settings and now emails generate from PHP scripts is being rejected due header "Received: (from apache#localhost)".
Searching various articles and forums I have come to know that webserver/computer cannot find its own name (so it comes out
as "localhost") when mails are being sent. I have every solution mentioned on the forums but still could not change the "localhost" part to my server name.
hostname at /etc/hosts is ok.
have added MASQUERADE_AS... to /etc/mail/sendmail.mc...
/etc/sysconfig/network is ok.
I desparately need help and wonder if someone can help me solve this problem.
function MAIL_NVLP($fromname, $fromaddress, $toname, $toaddress, $subject, $message)
{
// Copyright ? 2005 ECRIA LLC, http://www.ECRIA.com
// Please use or modify for any purpose but leave this notice unchanged.
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
return mail($toaddress, $subject, $message, $headers);
}
$message = "This is a test from the support dept";
$fromname = "myname";
$fromaddress = "myname#domain.com";
$toname = "myname";
$toaddress = "myname#domain.com";
$subject = "testing new script one";
MAIL_NVLP($fromname, $fromaddress, $toname, $toaddress, $subject, $message);
echo $subject;

Related

How to add custom header to PHP mail?

I have a mail function with the standard parameters:
mail($to, $subject, $message, $headers);
Where:
$headers = "From: admin#mysite.org";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
Now, I'm trying to get the sent e-mails to show 'My Site' as the sender instead of 'admin#mysite.org' but if someone responds to the mail it still needs to go to admin#mysite.org.
I've tried putting "My Site" in the "From" field before and after the e-mail address but it just appends to the address. I've tried appending it to the $headers variable but that messes the whole e-mail up. I've also tried adding it this way:
$headers .= "\r\nMy Site";
but that doesn't seem to do anything.
I know this can't be complicated as I've seen it done a hundred times, but I can't seem to find a straight-forward answer for this - how do I 'mask' the admin e-mail with the site name but still keep it as the address any response goes to?
Change your From: header to "From: My Site <admin#mysite.org>"
$headers = "From: My Site <admin#mysite.org>";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
From the PHP Docs.
There is the "From: something <something#something.com>"; header, and then there is also the optional fifth parameter of mail() which allows you to override the from setting that may or may not be set in php.ini.
<?php
$to = 'name#domain.com.au';
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: Name <noreply#domain.info>" . "\r\n";
$fifthp = '-f noreply#domain.info';
mail($to, $subject, $message, $header,$fifthp);
?>

PHP mail function not working based on the body of the message

so on my server I tried running:
mail('my#email.com', 'asdf', 'asklfdjksalfdsdaf I know I I know I');
and PHP sent the mail perfectly....but then when I changed the message to
mail('my#email.com', 'asdf', 'hahahahaa');
it did NOT send the email to me....
what can possibly cause this? the only thing that's different is the message body...I am completely baffled...
Here's the way I send messages with php and avoid sending to spam folder:
<?php
$to = "test#test.com";
$subject = "Test Email";
$message = "Test Email";
// normal headers
$num = md5(time());
$headers = "From: Mailer <mailer#test.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".time()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
#mail($to, $subject, $message, $headers);
?>
You should check your spam filter. It is possible that it is catching the message as being too short or not having enough discernible words, or any one of the other hundred things they'll check for.
If it is the spam filter, another thing that will help is adding different headers to help validate the email. Sometimes simply adding a realistic FROM in the headers can allow it through a spam filter. There's a default FROM set, usually in your php.ini but if it's some system generated name then filters can flag it.
http://php.net/manual/en/function.mail.php
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

PHP Mail - Can't Receive On Certain Mail Servers

Using the php mail() function to send out emails when a user requests a login.
It was working fine last week, emails were being received by all my coworkers who share the same mail server for our company. Now however, the emails are not being received by that mail server, but received on others (comcast.net, uservoice.com, gmail.com, etc.) just fine.
No error from the php mail() function so the emails are being sent, just for whatever reason they are all of a sudden blocked by our mail server.
No settings have been changed to the php scripts or the mail server.
Any ideas??? I have tried everything!
<?PHP
$timestamp = date('Y-m-d H:i:s');
$to = 'james.hickman#MYCOMPANY.com';
$from = 'support#MYCOMPANY.uservoice.com';
$subject = 'Admin Test';
$message = 'Just a simple test message! - '.$timestamp;
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "Organization: MYCOMPANY Support\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
if(mail($to, $subject, $message, $headers, "-f ".$from))
echo "Success!";
else
echo "Failed";
?>
If you are able to send mail out to other services and just not your own server then the problem is not with php's mail function. Php's mail function just sends out mail and you yourself said that u are able to send mails to other hosts. So the problem is not as devious as it sounds. Try and check if your server is out of disk-space.

custom php email settings?

I have this logic
$subject = "something.com Signup -
Please do not reply to this email. It was automatically generated.";
$body = "A new person has signed up to receive something updates:";
$headers = "From: webinquiries#something.com\n";
$headers .= "Reply-To: something#gmail.com\n";
// $headers .= 'Bcc: something#something.com' . "\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\n";
mail($email, $subject, $body, $headers);
which seems ok but one thing.... can i set the smtp info like this
server="smtp.something.net",
username="webinquiries#somthing.com",
password="asda.1sda",
port="587"
you can set the server in php.ini, but user\password as php's build in mail does not support authentication. you should look at a third party library (phpmailer) as the php mail() function's very under powered.

PHP sending emails

I tried to send an email vie PHP but got nothing. I don't see what I am doing wrong.
// Send an email.
$subject = 'Welcome to mypage';
$message = 'your registration went fine.';
echo $email;
$a=mail($email, $subject, $message );
echo 'Mail sent, a='.$a;
I checked that $email contains my email address and $a = 1 after running the code. Still my mailbox is empty. Why?
You probably don't have Apache configured correctly. That's why the email isn't sending.
Some mail servers require mail headers:
$header = "MIME-Version 1.0\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$header .= "From: ".$sendername." <".$fromemail.">\r\n";
$header .= "X-Mailer: PHP/".phpversion();
mail($email, $subject, $message, $header);

Categories