PHP email style - php

So on a website I am working on there is an automated email sent when you register. When it sends it shows the css.
$body '<span style="color:#444444;">Header</span>';
I also tried this code that I found online that had style=\"asdas\" then used a command to remove the slashes but that didn't work either. Is there a simple php code that will just simply embed the html in the email?

First, make sure you put the $body = as #JamWaffles suggests.
Next, are you setting your headers correctly?
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

You can find a pretty detailed tutorial here: http://css-tricks.com/sending-nice-html-email-with-php/
It shows importance of headers, HTML vs txt email and user desires. It should be a good starting point for you.
You can also add a tld check in your code and assume they would have an html capable email client/web interface(gmail/yahoo/live etc) or you can just ask them to provide you with this information and then send them the emails in the format they have asked you to.

Related

VBS and Tinymce

So I have a question that some more experienced individuals may be able to shed some light on and steer me in the correct direction. Here is what I have and what I am trying to do.
I have tinymce up and working just fine on a php webpage, of course that is until I go to submit it.
I am trying to use tinymce as the text editor for an email body that I am inserting into a vbscript then calling wsh to execute the .vbs. Everything works fine when I really don't edit the text. Just typing in and submitting without any colored text or other formatting.
However, if I do anything to the text at all it causes the .vbs not to execute. Upon opening up the unexecuted file I see that the "#" character for example when tinymce inserts the span color is causing it to hang.
I have googled and not found this issue presented is there something that I am missing? Or is there a better way to go about sending html emails from a webpage based text editor?
As I said as long as I don't really want to edit the text it works but I could do that plainly with a simple textarea but that defeats the purpose of wanting to be able to produce formatted emails.
Any and all suggestions are greatly appreciated. Thank you in advance for your time and help.
E-Mail Example:
// Sending an email with PHP
$to = $email; // Send email to our user
$subject = 'Email Sent with PHP'; // Give the email a subject
$message = '
<html>
<head>
</head><body>
<h3>Hey!</h3>
</body>
</html>
'; // Our message above including the link
$headers = 'From:nobody#nowhere.com' . "\r\n"; // Set from headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers); // Send our email

Is there an e-mail template file like *.oft, which can be opened in all e-mail programs?

Currently I'm writing a web interface which is full of data. I would like to export this data as an e-mail template, so you can edit the e-mail afterwards.
Is there a format such as *.oft, which can be read by all email programs?
I know that there is such a function in HTML (<a href="mailto:[...]">). Since the e-mail text is very long and I want to attach files, this doesn't seems to be a good solution.
Can someone help me?
There's no such format as you're looking for. The internet engineers who design email protocols and format concern themselves with what goes out over the network, but not with what's internal to the machine. Email is highly interoperable when sending and receiving messages as a result, but there's no analogous standards body for internal API's. Sometimes there are de facto standards that arise from a imitating the behavior of popular piece of software, but that hasn't happened for the email feature you're looking for.
Maybe you mean .EML files? I remember that this file can be opened with nearly all e-mail clients such as Outlook, Thunderbird etc.
As far as I can tell you can go one of two ways:
1 - Use a prebuilt solution such as the one by these guys at postageapp.com their API looks pretty simple and does everything you want to achieve.
2 - More time consuming, but you can create your own templete using PHP. I would go for something along these lines. This is a very simple way of doing it. You could write your own CSS in the head and go nuts. Just remember that tables are king when it comes to HTML email :) Once the template has been written, you could just pass through the $content to fill it....
sender.php
<?php
$email = "Hello, \n";
$email.= "Very <strong>impressed</strong> with your email! \n\n";
$email.= "Faithfully\n";
$email.= "Mr Example\n";
$to = "me#me.me"; // <-- Set this as yours for testing...
$from = "someone#nice.me";
$subject = "An email";
$headers = "From: Someone nice <" . $from . ">\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= nl2br($email); // <---- if your email contains newline characters - it will convert them to <br />
$message .= '<br />www.example.com';
$message .= "</body></html>";
mail($to, $subject, $message, $headers);
// ADD LOTS OF PROTECTION IF NOT HARD CODING :)
?>
To extend this - if you for example use Gmail, then you could use Google's SMTP to send it - so that the email wouldn't say 'Sent on behalf of'.
Just create a email using HTML without CSS. Any data or binary can be passed through PHP and then emailed to the recipient.
To get you started, Create a file using fopen();. PHP has other functions that would allow you to edit, open, search&replace and even convert a file to a format of your choice. This is equivalent to a .oft file if not better, because all emails are be sent in text or a html equivalent regardless of the email client.
If you'd would like some more info on how to create this, let me know.

how to send embed images in email using php and html

i know this question is asked several time and it is basic question but i searched last three days but i am still unable to send images in email.please help how can i embed images in my email that is which headers should i include in headers
i write the following code.
$to = "example#gmail.com";
$subject = "new account created";
$body = "New account has been created
<img border=’0' src=’http://www.example.com/myimages/track.php?MID=1111&SID=2222' width=’1' height=’1'>
" ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: admin#gmail.com";
$neww=mail($to,$subject,$body,$headers);
The reason you can't see your images in email is most email readers stript them out since they can be used for verifying valid email addresses which is a common tactic used by spammers. Your code screams tracking which only proves the point.
There is no way around this as the image filtering is done by the email clients and cannot be controlled by any code you write.
Check out this thread.
I posted a solution whereby you could use Mozilla Thunderbird to fetch the html image code for you which you can place in your script. The image will be embedded and would depend on no links or external content.
Look for my answer with the big screenshot of a lizard.
But, even despite that, users can still block images of all kinds. But emebedded images might be considered more acceptable than linked content - it depends on the client as to how images are handled.

Sending HTML Email Using PHP

I am trying to send html email using php. it is working fine on gmail, yahoo etc. but on my cpanel (Horde Email Client) the text is comming as an attachment and it is not showing any body.
These are the headers i am using
$headers = "From: " ."XYZ<noRelpy#xxx.com>" . "\r\n";
$headers .= "Reply-To: ". "noRelpy#xxx.com" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=us-ascii" . "\r\n";
I have also tried changing the charset to iso-8859-1 but still no sucess
Sending emails is hard, and fraught with serious security problems (mostly related to spam). It takes years to write code that sends email reliably.
Instead of trying to do it yourself, this is a place where a third party library makes sense.
We have been using PHPMailer for years: http://code.google.com/a/apache-extras.org/p/phpmailer/
It is difficult to write custom code that sends HTML e-mail, especially ones with embedded images or attachments. I have written a class to do this, but once you do, you realise there are a bunch of other features you need.
Using a third-party library really is a better choice here if your core product is not a mailing library. PHPMailer is good, another good option is
swiftmailer
Good luck!

Encoding issues with PHP contact form

I'm newbie to PHP, HTML and to programming at all.
I'm trying to create a contact form with PHP and HTML.
Everything is working fine, and i'm able to get the e-mails.
Except of one thing, If i'm trying to fill the form with another language, In my case it's hebrew, The mail i'm getting is with gibrish.
I saved the html file with the UTF-8 encoding, and i added the meta code. checked my outlook encoding and checked the mails i'm getting with a webinteface and it's still gibrish.
Any ideas?
First of all, try to "Echo" the content of the email to the browser instead of sending it out.
If it displays correctly, you are fine on the website part.
If the text is coming from a POST or GET form, you might need to convert it
with htmlspecialchars_decode(), see
http://www.php.net/manual/en/function.htmlspecialchars-decode.php
Then you can take care about the format of the email.
If you are sending email, you need to set the proper headers for the email just as you do for the website. For UTF-8, you would do:
$headers = "From: ExRobot <robot#example.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .="Content-Transfer-Encoding: 8bit";
If your subject also might include foreign languages you can set it to
"=?utf-8?B?".base64_encode($subject)."?="
If this does not help, post a complete sample email here as you get it. this will help a lot to understand what is wrong.

Categories