I send email without a problem but when i look on the headers i can see that before of the ones i create appears "X-Mailbox-Line: " and i have no idea why, does any one knows why ?
An example:
X-Mailbox-Line: From : <contacto#nidida.com>
Reply-To: <contacto#nidida.com>
MIME-Version: 1.0
Usually the X-* headers add added by receiver SMTP, so your code it's not the problem!
Related
I'm sending mail and using the wordpress SMTP plugin, however I have a problem that each time I send mail, on the debugging output I see the X-Priority header being sent which makes my MQS to drop with SpamAssassin.
I've set $phhmailer->SMTPDebug=false; and setting priority to null but it doesn't change anything.
The part of debug output looks like this:
["MIMEHeader":protected]=>
string(443) "Date: Tue, 5 Apr 2016 08:44:48 +0000
Return-Path:
To: web-z4CIb1#mail-tester.com
From: Example
Subject: WP Mail SMTP: Test mail to web-z4CIb1#mail-tester.com
Message-ID: <2edb8cb56706f6d09a29b49a66cf1ff0#example.com>
X-Priority:
X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
After quite a bit of poking around I managed to fix the issue by opening up the phpmailer class file, and commented out the following line:
$result .= $this->headerLine('X-Priority', $this->Priority);
This removed the X-Priority header completely.
If X-priority is removed from the header the email will be handled as priority 2 (normal). Instead of removing the header item, could you set it to 2?
You should be able to unset the header by using $mail->Priority = null;
according to this closed issue over at GitHub.
There can be other things affecting your spam score as well, not only the empty Priority variable.
Setting the $mail->Priority = null; is the correct solution (or do not set it at all as the default is null). However, in order for it to work you will also need to make sure you have a version of PHPMailer that has been updated with this patch.
I use the following code to send a mail:
$recipient="mymail#example.com";
$body="<html><body>This is magic</body></html>";
$subject="hi folks!";
$thisMail="sender#example.com";
$replyHeader = "MIME-Version: 1.0\r\nContent-Type: text/html; charset=UTF-8\r\nFrom: ".$thisMail. "\r\nReply-To: ".$thisMail."\r\n";
mail($sender, "Re:".$subject, $body, $replyHeader);
The mail is sent, but when I open it in a client mailer, the header seems to be broken. Everything after the first New Line (\r\n) is shown in the mail. Also some other header-contents are displayed. So the visible body of the mail looks like this in a mail client:
Content-Type: text/html; charset=UTF-8
From: sender#example.com
Reply-To: sender#example.com
Envelope-To: mymail#example.com
X-UI-Filterresults [... lots of stuff]
<html><body>This is magic</body></html>
What is going wrong there?
One (out of many) examples that show it "should" work that way: http://css-tricks.com/sending-nice-html-email-with-php/
Rather than relying on the mail function there are some really great libraries out there that handle headers, attachments, content and sending for you.
One of them - which is used by Laravel and other frameworks - is SwiftMailer, you should check it out.
They have some good documentation on setting headers too!
Honestly, you'll gain a lot from making use of the library and not reinventing the wheel.
SwiftMail does not send my email, while mail() does work. Same as here.
I added the EchoLogger but it does not print anything.
$message = Swift_Message::newInstance();
$message->setSubject('Test');
$message->setTo( $email );
$message->setFrom(ABSENDER);
$message->setBody($nl_text);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
$result = $mailer->send($message, $failures);
var_dump($failures);
The email is returned in $failures but why?
Update
In Swift_Transport_SimpleMailInvoker::mail I dumped out the parameters and got this:
$headers =>
string(208) "Message-ID: <1337173064.4fb3a4480b8dd#domain.de>
Date: Wed, 16 May 2012 14:57:44 +0200
From: news#domain.de
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
"
$extraParams =>
string(15) "-fnews#domain.de"
$to, $subject, $body is same as I used in mail(). Still no idea what the problem is.
Update #2
This worked fine for me:
mail($email, 'Test', $nl_text, "From: " . ABSENDER);
Disclaimer: This is not a solution but the workaround I used, because I did not have the time to debugger the framework and find a real solution. Feel free to use the information given above to debug yourself and post your solution here. I will gladly accept and upvote it.
I suggest you use the debugger and step to through the code behind send().
If you can not use a debugger you should have a look at the function mail in lib/classes/Swift/Transport/SimpleMailInvoker.php. There is a call to the internal mail function with an shutup operator (´#´). Maybe removing this operator can show you an error message. Also you can use var_dump() to dump the parameters passed there.
I had the same problem.
According to the documentation swiftmailer.org by default Swift_MailTransport::newInstance() uses parameters -f%s and that is why you got "-fnews#domain.de", to solve that place blank space between -f %s.
Your code now can be looks like that:
$message = Swift_Message::newInstance('-f %s');
I solved that problem simply passing null to __construct(). So my working code looks like that:
$message = Swift_Message::newInstance(null);
I hope it will help someone.
P.S. I use Postfix to send emails.
I was able to fix it. I was using noReply#mydomain.com in from header and this email account was not created. I created noReply#mydomain.com and my emails started working. I hope this helps somebody.
Looks like you're using the default transport mechanism which according to their docs uses mail() by default.
Serious drawbacks when using this Transport are :
Unpredictable message headers
Lack of feedback regarding delivery failures
Lack of support for several plugins that require real-time delivery feedback
source
If I were debugging this, I would find SwiftMailer's implementation of the mail() function and dump the arguments it's passing and compare them to your own working version of mail(). I don't have any experience with SwiftMailer but this seems like a fast option.
The problem is in Swift_Transport_MailTransport, private $_extraParams = '-f%s'.
The flag '-f' (see your code: string(15) "-fnews#domain.de") will fail in some situations. Code Igniter has the same "bug".
I found out on symfony if I just exit the function with "exit()" for example, swiftmailer won't send the mail but if I ended with
return new Response(); it sends fine. so I am not sure.
This may be really old, Had the same problem i solved it when using a shorter from email. seems like the maximum length after the # sign is 10. that is what i have tested so far.
example:
$sname = 'noreply#system.com';
->setFrom(array($sname => 'Some Header Title here'));
I am currently developing a website with the help of codeigniter and the ion auth library.
I am trying to use ion auth's standard functionality to reset a users password.
In the library there are 2 functions:
forgotten_password($identity)
forgotten_password_complete($code)
Both functions (in case validation goes through) send an email to the user. The functions themselves work, but the emails i receive are broken. The emails header is displayed as a part of the emails body. This is how a broken email looks:
Date: Fri, 18 Nov 2011 23:36:32 +0100
From: "Example.com" <admin#example.com>
Reply-To: "admin#example.com" <admin#example.com>
X-Sender: admin#example.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4ec6ddf0d26a3#example.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_4ec6ddf0d26b9"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_4ec6ddf0d26b9
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
New Password for test_user
Your password has been reset to: 0774b65f5e
--B_ALT_4ec6ddf0d26b9
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html>
<body>
<h1>New Password for test_user</h1>
=09
<p>Your password has been reset to: 0774b65f5e</p>
</body>
</html>
--B_ALT_4ec6ddf0d26b9--
However I was able to track down the line which is causing the trouble:
$this->ci->email->set_newline("\r\n");
When I comment out this line (in both functions mentioned above), the emails I receive when I reset a users password are fine.
Can someone explain to me the purpose of this line and wether or not it is a good idea to solve this problem by just commenting the line out.
I also found 2 questions
Problem sending email with Codeigniter - Headers sent in the message body
https://stackoverflow.com/questions/6740672/mime-format-email-breaking-sporadically-in-hotmail-php-codeigniter
referring to the same or at least a similar problem. As they are fairly old and haven't been answered yet, I created a new one. Hope no one minds.
Different operating systems use different characters to determine a new line (the place at which a line breaks to the next line.) In HTML, the equivalent is the <br> tag. Some (old? Mac) traditionally use \r, some (Unix) traditionally use \n, and others (Windows) traditionally use both (\r\n).
Codeigniter defaults to \n (see documentation), but the writer of ion auth overrode that to use \r\n, which is the standard.
So, the program parsing the email headers (which at my best guess is *nix-based) sees the non-Unix-standard \r\n line and starts spitting the headers out as part of the body.
To the best of my knowledge, you'll get by fine with just \n, which is why Codeigniter defaults to it. Every instance I've seen of people with troubles have been people using \r\n and getting the same problem you're having.
In CI, that setting defaults to '\n' when you comment that line out. The setting depends on the mail server that's being used by PHP. Sometimes postfix and some other servers will replace \r\n with \r\r\n causing errors, so in these cases it's best to just use \n, since the standard (RFC 822) requires \r\n.
I have a website, and in the "Contact" section I have a form which users may fill in to contact me.
The form is a simple form which action is a php page.
The php code:
$to = "email#domain.com";
$name=$_POST['name']; // sender name
$email=$_POST['email']; // sender email
$tel= $_POST['tel']; // sender tel
$subject=$_POST['subject']; // subject CHOSEN FROM DROPLIST, ALL TESTED
$text=$_POST['text']; // Message from sender
$text.="\n\nTel:".$tel; // Added to message to show me the telephone nr to the sender at bottom of message
$headers="MIME-Version: 1.0"."\n";
$headers.="Content-type: text/plain; charset=UTF-8"."\n";
$headers.="From: $name <$email>"."\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $text, $headers, '-fno-reply#domain.com');
Could somebody please tell me why this works most of the time, but sometimes I receive email whith no text and the subject line showing
=?UTF-8?B??=
I use outlook express, and I have read this System.Net.Mail and =?utf-8?B?XXXXX.... Headers
but it didn't help.
The problem is not in Outlook, because when I log in to the actual mailprogram where I fetch the POP3 emails from, the email looks the same.
When I right click in Outlook and chose "message source" then there is no "From" information.
Ex, a good message should look like this:
Subject: =?UTF-8?B?w5Z2cmlndA==?=
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
From: John Doe
However, the ones with problem looks like this:
Subject: =?UTF-8?B??=
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
From:
As if the information has been lost somewhere.
You should know also that I have a VPS, which I manage myself.
I use postfix as an emailserver, if thats got anything to do with it.
But then again, why does it work sometimes?
Also another thing that I have noticed is that sometimes special characters are not shown correctly (by both Outlook and the webmail).
For instance, the name "Björkman" in swedish is shown like Björkman, but again, only sometimes.
I hope anybody knows something about this problem, because it is very hard to track down for me atleast.
If you need more input let me know.
Thanks
When looking at PHP mail(), I see another line breaking: shouldn't you use \r\n as line endings?
And that Björkman example looks very much like your mail is not recognized as UTF-8 encoded.