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

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

Related

PHP Mail Message issue

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.

PHP mailer to send mail with HTML contents

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 :)

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 :)

Right way to process form text for sending email in PHP

I am currently processing a form with text and making an email out of the text.
I am facing two problems:
1) If I just take the text as is, I get \n\r that appear in the email whenever the person uses line breaks.
2) If I use nl2br() function on the input text, I get strings in my email.
Is there a correct or "best practice" way handling such situations?
Thanks,
Alex
You should add appropriate headers to your email
// To send HTML mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
before using nl2br()
// Then mail it
mail($to, $subject, nl2br($message), $headers);

Best way to do html e-mail, sending via php?

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);

Categories