I have a php mail set up to send, and it works completely fine on #gmail.com, but for some reason it doesn't reach any outlook e-mail.
I'll post my header, because I assume the problem is here
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\n";
$headers .= 'From: Me < '.$email_from.' >' . "\n";
I've tried using it without variables, without from, with reply_to, but nothing seems to reach outlook. Any guess on where the problem might be? Thanks in advance
It looks like it's not passing MS security checks.
Try and use https://github.com/PHPMailer/PHPMailer and SMTP. it'll pass more security filters but still may appear in the Junk folder.
Related
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));
When I try sending simple e-mails like this:
$email = 'example#mail.com';
$message = 'Hello.';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Example - No Reply <noreply#email.com>' . "\r\n";
mail($email,'Test',$message,$headers);
They work completely fine, but when I try to send a more complex message it just fails to do so :
$message = "<p>Thank you for registering with our system. In order to use it we need you to visit the following link:<br />
<a href='http://www.example.com/activate.php?q=$activation_link'>http://www.example.com/activate.php</a>
</p>"
I find this quite interesting. Is it possible that my host (iPage) has got some kind of filters that do not allow this? (Which is absurd) Or is it a mistake on my part?
Alright, this just got pretty obvious after more testing.
I am able to send all the e-mails if I exclude my domain name, which is pretty weird.
It's possible that my hosts filter is picking this up.
Going to have to see what's wrong with them.
Im trying to embed an
Google
for example. In the email however it shows all the html code. I think this might be for security reasons to avoid phising scams such as getting people to visit links they do not intend to. This is the best method i can think of as I am passing sensitive informations and just want the user to see the link as just the word 'Google'.
Note: google is being used here as an example only.
Take a look at Example #4 in the PHP documentation for mail
In particular, this part:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Are you setting the correct headers?
Straight from php.net
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
See more, here, Example #4 about sending html email.
i want to use click able link in email, but it is not reflecting in email sending through php mail function, below is my code
$url = "<html><a href='www.google.com'>Link</a></html>";
$message = "Hi test url ".$url." ";
$$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Admin <test#ex.com> \r\n";
#mail('test1#ex.com',$subject,$message,$headers);
Content which i'm getting from email:
Hi test url <html><a href='www.google.com'>Link</a></html> ##NEW##
You don't seem to be sending HTML mail correctly. Usually I will recommend using a third-party PHP library, like SwiftMailer, to simplify the process.
Edit: If you still wish to use php's mail() function, you will have to specify the headers correctly. This article could help.
To use the HTML in phpmailler:
$mail->isHTML(true)
You review the documantation
phpMailler
I am using php mail method to send HTML mails to people from my domain. I am using the following code to send mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html; charset=iso-8859-1' . "\r\n";
mail($id, $subject, $message,$headers);
However, the problem is that the code doesnt work when the size of message increases. It works fine for smaller messages.
Is there any way to overcome that ??
I resolved my issue. It was due to less number of breaking tags br in the html code. I introduced some br tags here and there and it flew :)