How to remove 'via' email address while sending mails using php [duplicate] - php

When I send a mail with PHP the destinatary gets a header like this one:
noreply#justwalk.it **via** de p3nlhg147.shr.prod.phx3.secureserver.net
I want to remove the "via" part. Most automated mails from websites don't have the "via" so it's certainly possible to remove it.
How do they do it?

Yes, you can get rid the "via" part. Here's the details:
1) SPF and DKIM
Firstly, you would need to set an SPF record for the domain you are sending emails from and enable DKIM as well. These are primarily for identifying your messages against spam.
2) "From: anything#yourdomain.com"
Secondly, make sure you are setting the “From: ” header to be an email address on the domain you are sending messages from. Don’t pretend to be someone else. Use “From: someone#abc.com” if you are sending the messages from abc.com, rather than anything else, such as blah#def.com, or yours#gmail.com, or whatever. If you want the recipient to reply to your Gmail email instead of your domain email, use the “Reply-To: ” header. “From: ” must always be the domain email that you are sending the email from.
3) "Return-Path: return#yourdomain.com"
Thirdly and most importantly, set the “Return-Path: ” header to be the same domain as that of the “From: ” header. Use the 5th parameter of the mail() function for this:
mail('recipient#example.com', 'Subject', "Message Body", $headers, '-freturn#yourdomain.com')
So the Return-Path of this message would be “return#yourdomain.com” (the email address immediately following the -f switch). The $headers parameter should contain all the necessary message headers. Make sure “From: ” is something#yourdomain.com.
After these steps and measures, Gmail should now completely trust your messages from yourdomain.com. The ‘via‘ field of your messages should be gone and the ‘mailed-by‘ field as well as the ‘signed-by‘ field should be correctly showing up as yourdomain.com.
Hope it helps!

I also fetched the same problem. But I have overcome the problem by using the following code:
mail('maaaa#abcd.com', 'the subject', 'the message', null,'-faaa#abc.com');
Make sure that last parameter is -f with the email address.
You can add the
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";<br />
mail('maaaa#abc.com', 'the subject', 'the message body in html format', $headers,'-faaaa#abc.com');
for the html message body in email.

This is probably added by your MTA and you didn't say which MTA you are using.
I'd recommend sending the mails not by PHP's mail() function but via SMTP, possibly even with SMTP-Auth, using something like PHPMailer.

#Mujibur is also right, But I used. But Didn't missed Headers too.
mail($to, $subject, $message, $headers, '-f'.$from_email_address);
And its successful to me, Let's check it from your side.

See what Google says about this here: http://support.google.com/mail/bin/answer.py?hl=en&ctx=mail&answer=1311182
All the best!

Related

PHP 'mail()' Function Not Sending Email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm using a basic script on a 1&1 hosted server:
$recipient = "email#domain.com";
$sender_name = $_POST['name'];
$sender_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=UTF-8"."\r\n";
$headers .= "From: {$sender_name} <{$sender_email}>"."\r\n";
$headers .= "Reply-to: {$sender_name} <{$sender_email}>"."\r\n";
mail($recipient, $subject, $message, $headers);
..but for some reason am not receiving any emails, nor any errors as per PHP mail() function not sending email instructs.
I thought this may be a server issue but 1&1 states that it is fully supported. I've also sent emails from this server/hosting before using just a recipient, subject and body and so I'm rather unsure as to why it is not working now!
UPDATE
Sending without headers, i.e.:
mail($recipient, $subject, $message);
..does work, so it would appear to be an issue with using the headers?
There may be many reasons, for example you should study what SPF is.
The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)
You should use in the From something ending in #yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)
Errors in header does affect the mail delivery. if you send email with wrong headers, for example, let's say the email of the user is user#email.com and his name is "user user", and you send the email to user#email.com it might cause the email to go in spam or not accepted at all if it doesn't match on server.
Gmail, for one, has a name associated with every email id. if you put a wrong name with the email, there's a chance the email might not show up in inbox or sometimes even spams.
"But in the link I attached the example given uses a 'from' header set by a form input?"
if you want your users to be able to send email to you, best idea would be to use your own email address as the sender email. E.g. if your website is at website.com, configure an email like "contact#website.com" and configure your script to use this as From header, you can send it to your own email at the same domain(website.com) or any other email which you authorize. You can add the users's actual details in the mail. that'll ensure the successful delivery of the email always.

PHP Mail is Being Sent to Spam [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 7 years ago.
I know that there are many similar questions on this site, but none of them helped me.
I have the following PHP code:
<?php
$to = "mymail#inbox.com";
$from = "no-reply#heygee.com";
$subject = "Confirm your registration!";
$message = "Please follow this link to confirm your registration: www.bit.ly/32106";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: HeyGee! <no-reply#heygee.com>" . "\r\n" .
"Reply-To: mymail#inbox.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$ok = #mail($to, $subject, $message, $headers, "-f " . $from);
?>
Let's say mymail#inbox.com is my test e-mail. Whenever I send the mail to my address, I always receive the mail in my Spam folder. Why is that? Are there any corrections or tricks to be made to prevent the mail from arriving in Spam?
Thanks.
The reason why your mail is being sent to Spam folder is either because of the content of your email or that the receiving side is not able to verify if the email actually came from the stated domain in the from address, i.e., if the sender (you) are authorized to send email on behalf of heygee.com.
Content part is easy to correct. You need to avoid bad grammar, ambiguous links (e.g links which say google.com but point to example.com), etc. Your message should be well worded (exclude those words frequently found in spam mails), and preferably include an unsubscribe link as well (if sent to a mailing list).
Now comes the second and difficult part. The domain that you are writing in your from address should be the same domain from which you are executing this mail script or should be authorized by this domain's TXT records to send mail on its behalf. The simplest way to go about this would be (provided you have DNS access to the sending domain name) to add a TXT SPF record permitting the IP of the server your script resides on to send mail on its behalf.
Example SPF record:
"v=spf1 ip6:1080::8:800:200C:417A/96 -all"
The above record means Allow any IPv6 address between 1080::8:800:0000:0000 and 1080::8:800:FFFF:FFFF.
Checkout:
SPF (Wikipedia)
Also, you may have a look here http://www.openspf.org/
Now if you don't have DNS access, then simply change the domain name of the from address to the domain name of the server and it should fix it.
Hope it helps.
This is not related to your programming by itself. Filtering e-mail as spam is done on the client side and there is nothing you can change about that (if it were, millions of spammers would be doing it)
The problem you have is that your e-mail looks like spam. Try to write a better e-mail, with a body longer than 1 line. I would also remove the exclamation mark from the subject; that's also something that makes it look like spam.
If your spam detection system gives you detailed information on why it was labeled as spam (SpamAssassin can do that depending on how it is configured), then use that information to fix the e-mail that you send.

Mail ends up in junk folder - PHP contact form [duplicate]

I wrote a PHP script to send emails.
My script is like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: abc#yahoo.com' . "\r\n";
// Email Variables
$toUser = "someone#yahoo.com"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?
Please try this:
$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";
mail($to,$subject,$body,$headers,"-f$from");
Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
1. Check mail content
As others have hinted it is probably marked as spam because your mail looks like spam.
I am not sure if you the script that you have posted is the actual one that you are testing.
If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9
X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
version=3.2.5
Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.
2. Mail server's IP
Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.
3. Blocklists
Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.
Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.
Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.
Hope that helps!
**This Works Perfectly fine for me**
$to="reciever#reciever.com";
$subject="This is Your Message";
$from = 'Sender <noreply#sender.com>';
$body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
$headers = "From: " .($from) . "\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($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";
mail($to,$subject,$body,$headers);
I was having the same problem:
The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.
But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.
As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.
So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.
Another one is the html contents without the alternative plain text contents, but, this one is less important.
I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)
On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
Make sure you send your e-mails from an existing account on your server/domain.
Make sure you have the reply-to address in your header.
These are the basic things you can try.
if your website domain is mydomain.com then in From headers make sure to use someone#mydomain.com
Remove the Content-type: text/html and add $headers .= "X-Priority: 2\nX-MSmail-Priority: high"; to get rid of Spam. This method has been tried and tested.
the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?
You've got two solutions:
use Yahoo's SMTP using abc#yahoo.com credentials to send mail from abc#yahoo.com;
use other from, with your own domain;
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..

PHP mailer setting from address in mail function

Ok so I set up a php mailer on 2 separate pages on a site I am working on. I had previously worked through everything in the mailer on a site I built and it was straight forward how to set the email after setting all the variables:
mail("$email",
"Receipt: $thesubject",
"$message",
"From: $replyemail\nReply-To: $replyemail");
So this was what was at the end of the contact (processing) page. I have $email and $replyemail being put into the $message and they come out correctly in the message that gets sent to my email specified by $email.
The part I don't really understand is the address the message says it is coming from is not that $replyemail but instead it says it is being sent from:
rtl.srv#gmail.com
I saw a few posts that were similar but none of them fixed the issue, I followed this and checked to make sure the servers php.ini files had SAFE_MODE = off. Then added
'-f $replyemail'
to the end of the mail function above like that link advised but it didn't change anything... I saw somewhere else that it explained you may have to add the email address to the file /etc/mail/trusted-users but the issue is that email is dynamic. Since that email name is whatever the user input as their email. Then the email is sent to the site admin to review, and I want the email to say it is from the users email that filled out the form.
I know the variables are set correctly because they are being printed out correctly inside the message of the email. So if anyone has any idea why this is happening or how I could go about fixing it I would appreciate any insight.
The project is built in wordpress but I just dropped the files onto the server through SSH, not sure if that has anything to do with it.
Thanks,
-Alan
There are a number of issues that can cause this, and I encountered this issue a while ago when I built my site. I solved it by first creating a function to handle the mailout for me:
function mailouthtml($to, $title, $body, $from){
if(!isset($from)){
$from = 'Default Sender<address#example.com>';
}
$header .= "Reply-To: $from\r\n";
$header .= "Return-Path: $from\r\n";
$header .= "From: $from\r\n";
$header .= "Organization: Example.com, Inc.\r\n";
$header .= "Content-Type: text/html\r\n";
mail($to,$title,$body,$header,"-f $from");
}
Let me break this down a bit. The function calls for a To address, the email title, the email body, and the From address. The From address is used to add information to the email header. The header information of your email is what tells your mail server what to do with your email, and it needs a bit of info in order to handle the message properly.
The mail() function in PHP is formatted as follows:
mail($to,$title,$body,$headers,$additional_parameters);
The mailouthtml() function I've created here constructs the header manually, and adds the additional parameter "-f $from" to set the "From" field explicitly. The $from variable is optional in the function call; if it isn't present, it sets a default. You can find more information on the mail function Here.
Note the following:
Most MTA's require a Reply-To, Return-Path and From field, or it may be flagged as spam.
Content-Type is required tell what type of content the mail server is delivering, typically text/html or text/plain.
I have an if(){} statement that sets a default address if none is specified. You can omit 'Default Sender' if you would rather not specify a name. You can also change that to whatever you'd like.
Organization is optional.
I would also recommend you have SPF enabled on your domain name, and DKIM signing on your messages. These are both implemented via DNS entries for your domain name. If you don't have access to that, no big deal; they're meant to control spam.
Also, if you have a dedicated server and your own IP address, make sure you have a Reverse DNS record set up. This will also help foreign MTA's identify your message as authentic.
don't make this to yourself. Use some mature library like phpmailer or swiftmailer, they will help you to avoid these kind of troubles...I know there are more includes, etc, but there is not point to give fight to this. If you still want to do this, try setting the header Returh-path

Basic phpmailer question

I am using phpmailer to send my newsletter to my subscribers.
I set my headers as following:
$headers = "From: Sales - Blah Blah <sales#blahblah.com>";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
NOW, in the delivered email, for example in a gmail account, if you press the "show details" link, the following appears.
from Sales - Blah Blah MIME-Version: 1.0
sales#blahblah.com via ecbiz103.inmotionhosting.com
to blahblah#gmail.com
date Wed, Aug 3, 2011 at 11:02 AM
subject sales !
***mailed-by ecbiz103.inmotionhosting.com***
HERE IS THE QUESTION:
HOW CAN I MAKE IT ACTUALLY SEND THE EMAIL FROM THE ACTUAL EMAIL ACCOUNT, that is "sales#blahblah.com" and be able to see the outgoing emails on my "sent" tab?
I guess, when this happens, the last line mentioned in bold would say
"mailed by blahblah.com"
Regards, George
PHPmailer as in http://phpmailer.worxware.com? Or do you mean PHP's built-in mail() function? It would appear you're using mail(), since you're building your own MIME message. Don't do that. It's too much main and unreliable. use PHPmailer (at the link mentioned earlier) or Swiftmailer to do that sort of thing for you.
Either way, if you want the mails you send to show up in your account's "sent" folder, you'd have to send the emails via your own email account using blahblah.com's mail server. Another option would be to set a BCC: to silently copy yourself on each mail, and have a mail rule on your account to divert those mails to a folder.
The simple answer is: you cant.
All phpmailer does is connect to the mail server to send the mail. It does not link to your actual e-mail account in any way at all.
EDIT:
Also, you will not be able to remove the ecbiz103.inmotionhosting.com reference as that is the hostname of the server that is sending the mail. A mail server runs on one IP address, this IP has a hostname, in this case ecbiz103.inmotionhosting.com.
You don't have a newline after the first line of headers, specifically the From header.

Categories