embed link in php mail function - php

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.

Related

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

php mail sending problem. Server not accepting html tags

I developed a simple form with mai lsending function. When the file is in our server all the functionality worked greatly. But when the files moved to our client server, in mail sending we are facing some problem. What ever HTML code i used it's simply displaying in the same format. The HTML rendering is not happening properly.. Whether problem in the server or i have to change my php code??
I believe you have setup the correct Content-Type: HTML on your email functionality. Please see: http://php.net/manual/en/function.mail.php#example-2881 for more information.
Quick Info:
// 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";

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