PHP Mail Message issue - php

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.

Related

Email not sending to outlook.com

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.

how to use clickabe link (href link) in php mail

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

Extra characters in PHP email "from" field

I'm trying to send email from PHP, and although it's working, I'm noticing that I'm getting a lot of extra stuff in the "from" part of the email. The extra stuff, I'm assuming, is
information from my server?
For example, if $from = "myname", instead of "myname" only coming through in the email from field as is, I get something like:
myname#p3nlhg.phx3.secureserver.net
Here is my PHP I'm playing with, the important part being my $from var:
$from = "myname";
mail($to,$formSubj,$formMssg,$from);
Honestly that's all I have, nothing more or less (as far as the $from is concerned). How can I clean this up or make it so that only the plain value of $from, which is in this case "myname", comes out?
The 4th parameter of the mail function doesn't work this way. It expect header information. To achieve what you want to do use:
$header = "From: myname <no-reply#test.com> \r\n";
mail($to,$formSubj,$formMssg,$header);
You shouldn't use a lonely myname either. You need a valid email addess string: myname <no-reply#test.com> or no-reply#test.com. If you just put myname, PHP will try to interpret it as an email address. That's why you're getting myname#p3nlhg.phx3.secureserver.net. p3nlhg.phx3.secureserver.net must be the hostname of your server.
A nice thing about the header parameter is that you can use it to specify other less common fields. e.g.:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
Notice that you need to place a carriage-return/line-feed (\r\n) at the end of each header attribute. A simple line feed will not work.
According to the mail documentation, you're using $from as the $additional_headers argument.
Instead, change $from to an appropriate header. For example,
$from = "myname";
$headers = "From: $from <user#example.com>";
mail($to, $formSubj, $formMssg, $headers);
According to the documentation for additional_headers,
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
It's coming from the mail server that you have installed in your server, try to switch to another one, like postfix, courier or someting else.

PHP mail(): Header appears in mail body

I have a problem with a mailing application I'm currently developing with php on a linux server. After sending an email to a bunch of different addresses with different clients on it, sometimes these mails can't be read by the receivers.
For example the body appears to start with this:
boundary="=_2cac04098ebf51c342bd57eab2200e38"
Message-ID: <lo5huc.id4ip6qutsch.lforce.de>
Date: Mon, 11 Jul 2011 06:01:24 +0200 (CEST)
--=_2cac04098ebf51c342bd57eab2200e38
I really have no clue what's happening to my mails. Each line in the header is separated by \n, the boundary entry has a leading \t. Though the client seems to read a line break which is not there while parsing my header. It also happens in other parts of the header.
Has anyone ever had a similar problem? Please help me!
Andy
UPDATE: I'm pretty sure it's no coding error. I've been coding this mail stuff for years (even wrote my own mail client) and it worked perfectly. Right now we use the RMAIL class which is also from a bigger open source project. I think it's more like a problem with my system configuration... but that's just a guess.
Make sure you seperate every header line correctly, for instance:
<?php
//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";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I suggest using PHPMailer, easy to use, takes care of all nesseccery headers, easy attachment sending, multiple recipients etc.
http://phpmailer.worxware.com/index.php?pg=phpmailer

Sending emails with styling and formatting [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Php mail: how to send html?
formatting email in php?
I'm using PHP to send emails, like this:
$to = $emailAddress;
$subject = "qwerty";
$message = "foo" . PHP_EOL . "bar";
$headers = 'From: "asdf" <email#email.com>';
mail($to, $subject, $message, $headers);
When I attempt to put HTML code within the message, it just sends the actual HTML as plaintext. This leads me to ask - how can I format emails as I can format webpages?
Make sure you're setting your headers for text/html, like so:
// 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 Example #4 in the PHP Manual for the full example.
To add style to your email, you first need to add a header as mentioned by jmort253, like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Once you have added this to you header. You can do styling in the actual message, ie:
$message = "<html><body><h1>Welcome</h1><p>Thanks for the email</p></body></html>";
Make sure that you do inline CSS or put it in the header, don't put it in an external CSS file. As for images, you'll need to include full paths to your server, so that the client mail application can find the image on the web.
Hope this helps.
I recommend not reinventing the wheel. Instead use phpmailer class or something similar. Will solve many other upcoming problems as well :)

Categories