i have a PHP variable that i construct like:
$msg_gifted='<body style="border:3px solid
black;padding:5rem;width:1000px;margin:auto;margin-top:30px;text-
align:center;">';
$msg_gifted.='<img src="/logo.png">';
$msg_gifted.='<h1>It is a mail </h1>';
$msg_gifted.='<p>From: ';
$msg_gifted.=$_POST["useremail"];
$msg_gifted.='</p>';
$msg_gifted.='<p>Amount: GBP';
$msg_gifted.=$_POST["amount"];
$msg_gifted.='<Some text </p>';
then i am sending this variable with mail
mail($recipient_gifted,$subject_gifted,$msg_gifted,$mailheaders_gifted);
everything works fine.
When i am adding some more staff to the variable then for some reason the mail never arrives
$msg_gifted='<body style="border:3px solid
black;padding:5rem;width:1000px;margin:auto;margin-top:30px;text-
align:center;">';
$msg_gifted.='<img src="/logo.png">';
$msg_gifted.='<h1>It is a mail </h1>';
$msg_gifted.='<p>From: ';
$msg_gifted.=$_POST["useremail"];
$msg_gifted.='</p>';
$msg_gifted.='<p>Amount: GBP';
$msg_gifted.=$_POST["amount"];
$msg_gifted.='<p>Some Text</p>';
$msg_gifted.='<p>';
$msg_gifted.='1000';
$msg_gifted.='</p>';
is there a limit for the variables?
You should consider using something like PHPMailer or SwiftMailer for sending E-Mails.
Most likely you got something wrong with the headers of the E-Mail. It's difficult to get them right, especially, when using mail for the first time.
Also, as far as I know, there's no such thing as a variable limit for mail(), have you already checked your server error logs?
Greetings
Edit:
As I thought it's a header based error.
i figured out it has to do with the headers.
the whole mail headers variable is:
$mailheaders_gifted = "From: " . $support_email . "\r\n";
$mailheaders_gifted .= "Reply-To: ". $support_email . "\r\n";
$mailheaders_gifted .= "MIME-Version: 1.0\r\n";
$mailheaders_gifted .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
I also tried :
"Content-type:text/html;charset=UTF-8" . "\r\n";
I still recommend to use one of the libraries I mentioned above.
Following from the PHP Docs for the mail function could solve the problem:
Note:
If messages are not received, try using a LF (\n) only. Some Unix mail
transfer agents (most notably » qmail) replace LF by CRLF
automatically (which leads to doubling CR if CRLF is used). This
should be a last resort, as it does not comply with » RFC 2822.
I finally managed to solve this. it was not a problem of how to setup the variable, but how to setup the headers.
i needed to edit my headers like:
$mailheaders_gifted[] = 'MIME-Version: 1.0';
$mailheaders_gifted[] = 'Content-type: text/html; charset=iso-8859-1';
$mailheaders_gifted[] = 'From: My Web Site <mymail#example.com>';
then the mail function should be:
mail($recipient_gifted,$subject_gifted,$msg_gifted,implode("\r\n",$mailheaders_gifted));
Related
i am trying for send mail using php.My mail go to spam and some other errors are also in mail.
My header code is
$header_mail="select content from mail_header where id='1'";
$header_mail2=mysql_query($header_mail);
$fet=mysql_fetch_array($header_mail2);
$content= htmlentities($fet['content']);
$Headers = "From:$content\r\n" .
"Reply-To:$content\r\n" .
"Content-type: text/html; charset=UTF-8 \r\n";
$Headers.= "MIME-version: 1.0\n";
$Headers.= "Content-type: text/html; charset= iso-8859-1\n";
data in $content is zamisoft<zamisoft.com> but i got the mail as with
from: Zamisoft<
reply-to: Zamisoft<,
zamisoft#gmail.com>
I got the these message in mail
"Be careful with this message. Many people marked similar messages as phishing scams, so this might contain unsafe content. Learn more "
Mail is going to spam and errors are in header section part of mail.
Any body help me for solve these issue?
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
remove the htmlentities() from $content= htmlentities($fet['content']); and then try!
Since you are already setting the Content Type and Character Encoding, the contents of the array $fet['content'] will be read properly by the browsers!
htmlentities() converts the html tags to htmlentities (eg. < to <) which is what you are facing!!
Try it and let us know if the problem persists
Remove the line "Content-type: text/html; charset=UTF-8 \r\n"; as you have defined the header in the last line of header.
Add $Headers .= 'X-Mailer: PHP/' . phpversion()."\r\n"; at the last line of your code.
It tells which version of php is being used!
Also the email address should be a valid one as well!!
The following headers are sent using PHP's mail() function:
$emailheaders = "From: " . $sender . "\n";
$emailheaders .= "Return-Path: " . $sender . "\n";
$emailheaders .= "MIME-Version: 1.0\n";
$emailheaders .= "Content-type: text/html; charset=UTF-8\r\n";
mail($email, $subject, $body, $emailheaders);
It works fine, except Return-Path: is reset to nobody#server.com, or at least this is what shows up when viewing extended headers for emails received using the above headers. Naturally this means that bounce emails are not received.
Does Apache reset the headers, and in this case why, or am I using mail() incorrectly?
What can I do to prevent this from happening. Using mail()'s fifth parameter (e.g. -f sender#server.com) is out of the question as PHP is in safe mode and the provider will not change that. I suppose that there isn't some way to allow the fifth parameter for certain users despite safe mode being on.
The server is running Apache 2.2.3 and PHP version 5.1.6.
The server's Mail Transfer Agent (MTA) is overriding the return-path. For example if using Exim:
Set the return-path in the /etc/exim/exim.conf configuration file:
return_path = sender#example.com
If you don't have access to the server config or the mail() fifth parameter then there's probably nothing you can do.
You are splitting the headers using \n but according to PHP it should be \r\n (see Which line break in php mail header, \r\n or \n?).
Perhaps thats the reason why the header isnt send correctly.
I've never done html e-mail before, I've just set up php mail using http://www.postmarkapp.com
I was wondering how I would go about sending php mail as html?
Does anybody have any previews of a php page sending html e-mail I can look at to get the jist of how it works?
Currently I'm just putting text into a variable and sending it as a message, how is it done for html?
Regards
Do you still want to use Postmark to send emails?
In Postmark, you set the TextBody property to the text version of your message, and the HtmlBody property to the html version of it. It is good practice to always include both. Depending on whether your user's email client supports HTML or not, the appropriate message form is rendered. Read more on this here.
Edit: Added an example. I generally like splitting my string into separate lines so that I can indent it nicely like a real HTML file. Of course, if you used templates, that would make it so much better.
$htmlBody = "
<html>
<body>
Thank you for using our app!<br />
- Super Awesome App Team
</body>
</html>
";
http://phpmailer.worxware.com/
This is the best class I've found to send mail with PHP. It allows HTML formatting with alternate plain text part, as well as attachments. It also seems to filter out spam quite well when used for online forms.
Put the html code inside the variable where you need as you are doing while creating web pages and set the mail header to text/html.
$headers.= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.= "From: eaxfd#gmail.com \r\n";
$headers.= "Reply-To: eaxfd#gmail.com \r\n";
mail($to,$subject,$message,$headers);
You just have to include html headers in your call to the mail() function:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1';
mail($to, $subject, $message, $headers);
I have a website in which I send a confirmation mail as part of the registration process.
Some time ago, I had some troubles with the mails I sent since I used no headers (PHP mail function).
Once I put some headers, I've gotten more responses from users, but I suspect that not every message reaches its destination.
How can I be sure that the messages reach their destination?
Which are the headers that can be considered a 'must'?
This is the code of my SendMail function
mail($to,
$subject,
$message,
"MIME-Version: 1.0\n".
"Content-type: text/plain; charset=ISO-8859-1; format=flowder\n".
"Content-Transfer-Encoding: 8bit\n".
"Message-Id: <" . md5(uniqid(microtime())) . "#mysite.com>\n".
"Return-Path: <admin#mysite.com>\n".
"X-Mailer: PHP v".phpversion()."\n".
"From: admin# mysite.com");
You should use external library for working with e-mails in php like PhpMailer , SwiftMailer or Zend_Mail. All your problems will go away.
The headers need a white space at the bottom to separate the header from main body.
Tools like Spam Assassin will give you a big mark down for that.
Also you should use \r\n as a line terminator instead of just \n
From PHP.net
Multiple extra headers should be separated with a CRLF (\r\n).
The headers seems quite good to me. The only glitch I see is an extra whitespace in the From header.
I'm sure you already checked it, but just in case ...
"From: admin# mysite.com");
should be (?)
"From: admin#mysite.com");
This is a working mail function I'm using for html mail and variable $return is defined to get error report from mail server in case of fail delivery.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$from.'>' . "\r\n";
$return = '-f'.$from;
#mail($to, $subject, $msg, $headers, $return);
you can see more detail at here sugunan.com
The headers look ok, except for the details pointed by #Eineki. Also if you are using Windows you need to send the $to param in the form "user#mail.com" and not "Username ", because it may cause trouble, due to the way the mail() function is implemented on windows platform, the "to" address may be parsed incorrectly.
You should add a Date: header (its mandatory by RFC5322) and some mail-clients may assume January 1 1970 as an e-mail date if none is given (and it gets lost between all the other old messages).
I am trying to send an email from a site I am building, but it ends up in the yahoo spam folder. It is the email that sends credentials. What can I do to legitimize it?
$header = "From: site <sales#site.com>\r\n";
$header .= "To: $name <$email>\r\n";
$header .= "Subject: $subject\r\n";
$header .= "Reply-To: site <sales#site.com>" . "\r\n";
$header .= "MIME-VERSION: 1.0\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$phpversion = phpversion();
$header .= "X-Mailer: PHP v$phpversion\r\n";
mail($email,$subject,$body,$header);
Don't use HTML in your email.
Send it via a legitimate mail server with a static IP and reverse-DNS (PTR) that points to the machine's real host name (and matches a forward lookup).
Include a Message-ID (or ensure that the local mailer adds one for you).
Run your email through SpamAssassin and see which bad-scoring rules it matches. Avoid matching them.
Use DomainKeys Identified Mail to digitally sign your messages.
I just successfully tried the following from my Yahoo! Web Hosting account:
$email = "me#site.com";
$subject = "Simple test";
$body = "Simple test";
$header = "From: site \r\n";
$header .= "To: $name \r\n";
$header .= "Subject: $subject\r\n";
$header .= "Reply-To: site " . "\r\n";
$header .= "MIME-VERSION: 1.0\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$phpversion = phpversion();
$header .= "X-Mailer: PHP v$phpversion\r\n";
mail($email,$subject,$body,$header);
However, you have some duplication in your header you should only need to do the following:
$email = "me#site.com";
$subject = "Simple test";
$body = "Simple test";
$header = "From: site \r\n";
$header .= "MIME-VERSION: 1.0\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$phpversion = phpversion();
$header .= "X-Mailer: PHP v$phpversion\r\n";
mail($email,$subject,$body,$header);
In addition to Ted Percival's suggestions, you could try using PHPMailer to create the emails for you rather than manually building the headers. I've used this class extensively and not had any trouble with email being rejected as spam by Yahoo, or anyone else.
There is also the possibility that 'sendmail' (which is underneath the PHP mail() function) needs extra parameters. If you have a problem with return headers (such as Return-Path) not being set with what you set them to be, you may need to use the fifth mail() parameter. Example:
mail('recipient#domain.com', 'Subject', $mail_body, $headers, " -f sender#domain.com");
There is some further evidence that true vanilla sendmail may have problem with this! Hopefully you have 'postfix' as PHP's underlying mail() support on your target server.
In addition to Ted Percival's suggestions, make sure that the IP address the email is coming from is a legitimate source for email according to the SPF record of site.com. If site.com doesn't have an SPF record, adding one (which allows the IP address in question, of course) may help get the emails past spam filters.
And if absolutely do need to use HTML in your email, make sure that you also include a plain text version as well; you'd use the content type of "multipart/alternative" instead of "text/html".
Ted's suggestions are good, as are Tim's, but the only way I've ever been able to reliably get email through to Yahoo/Hotmail/etc is to use the PEAR email classes. Try those & (assuming your server is OK) I can pretty much guarantee it'll work.
Ted and Tim have excellent suggestions. As does Shabbyrobe. We use PHPMailer and don't have any problems with spam filters.
One thing to note is that many spam filters will count NOT having a text version against you if you are using a MIME format. You could add all of the headers and the text version yourself, or just let PHPMailer or the PEAR mail library take care of that for you. Having a text version may or may not help, but it is good practice and user friendly.
I realize that your code sample is just that - a sample, but it is worth saying: Do not ever just drop user provided data into your mail headers. Make sure you validate that it is data you expect. It is trivial to turn a php mail script into an open relay, and nobody wants that.
Check rfc 822 and rfc 2045 for email format. I find python's Email class really easy to work with. I assume php's PEAR does the same (according to earlier mails). Also the header and the body are separated by a "\r\n\r\n", not sure if your code automatically inserts that, but you can try appending that to the header.
I dont think that DK/SPF might be necessary (since there are lots of webservers out there without DK/SPF support). There can be alot of factors that might be causing it to get blocked(atleast 10K different criterions and methods.. p0f,greylisting,greylisting, blacklisting etc etc). Make sure that your email is properly formatted(this makes a BIG difference). Look into libraries that generate the complete header for you.. that way you have least chances of making any mistake.
Adding a SPF record is very easy. You should try.
This one is for dreamhost plus googlemail
You should also ad you webserver ip address (in my case, the line before googlemail)
The last line tells the server to do a soft reject (mark as spam but don't delete) I'm using it instead of "-" (delete) because google documentation says so :-)
It's a TXT record
v=spf1
ip4:64.111.100.0/24 ip4:66.33.201.0/24 ip4:66.33.216.0/24
ip4:208.97.132.0/24 ip4:208.97.187.0/24 ip4:208.113.200.0/24 ip4:208.113.244.0/24
ip4:208.97.132.74 ip4:67.205.36.71
include:aspmx.googlemail.com
mx ~all
Hope it helps