I am using PHP's mail() function to generate mails. Generated mail looks absolutely fine with correct email ids in 'To' and 'Cc' but mail gets delivered to 'To' only and not to 'Cc'.
Here is the code
$headers = "From: xyz#abc.com \r\n";
$headers .= "Reply-To: xyz#abc.com";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Cc: email1#abc.com ; email2#abc.com" . "\r\n";
$headers .= "X-Mailer: PHP/". phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1". "\r\n";
mail($to, $subject, $message, $headers);
Our organsation uses 365 for mails, and this issue has mostly cropped up since we started migration. I went through the php mail log and it seems to be fine to me.
How to fix this issue? Any suggestions?
PS. I feel that this issue has cropped up only since we moved to 365 some time ago. Also, does id 'xyz#abc.com' (sender) need to exist?
$headers .= "Reply-To: xyz#abc.com";
Where is the "\r\n" on this line?
For a proper and standardized PHP mailing library which will help your team to properly build emails, take a look at:
https://github.com/PHPMailer/PHPMailer
Replace the ; to an , in your CC line:
$headers .= "Cc: email1#abc.com ; email2#abc" . "\r\n";
Or send your mails over IMAP with a class like PHPMailer https://github.com/PHPMailer/PHPMailer
Related
I mail using php mail function to send e-mail. In my dev server its working fine but in live server e-mail goes to spam folder.
<?php
$to = "example#gmail.com";
$subject = "Registration";
$from = "example1#gmail.com";
$content = "Test";
$headers = "From: Test <" . strip_tags($from) . ">\r\n";
$headers .= "MIME-Version:1.0" ."\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$res = mail($to,$subject,$content,$headers);
$headers = "From: Test <" . strip_tags($to) . ">\r\n";
$headers .= "MIME-Version:1.0" ."\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$res2 = mail($from,$subject,$content,$headers);
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
https://github.com/PHPMailer/PHPMailer
answered by mrdognose
and use full headers..
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
Prevent sent emails treated as junk mails using php mail function
The one email From:support#lead.com works fine. But when changed to john.doe#lead.com it doesn't work? See below.
Both are valid email addresses (fictitious for this example) in the domain from which they are sent.
I have the question into Netfirms support too. I expect to move to phpmailer or API to a ESP (e.g., mailchimp) account soon, but this is just bugging me that the little change breaks the email function.
Code:
Works:
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: support#lead.com' . "\r\n";
$headers .= 'Bcc: bcc#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#mylead.com")) echo ("Message delivery failed");
Doesn't Work: (only changed support to john.doe):
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: john.doe#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#lead.com")) echo ("Message delivery failed");
Don't know how this really should matter, but you're mixing \n and \r\n in the headers, which may confuse your mail server... Would you mind to try this out?
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);
?>
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.
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.