VBS and Tinymce - php

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

Related

Android sending mail with Base64 image

I'm trying to send an email with an image taken with the camera from a smartphone. So far, it's going great. I'm sending a post request to my hosted php script from the device, with a Base64 string as post data which represents the picture taken by the user. Although, when I try to mail the image, it doesn't really seem to work out because I get the plain string instead of the image. What's the best technique to solve this and get the image in my mail instead of 2mb ofplain text? ;)
This is my php script:
$to = "secret#gmail.com";
$subject = "New bug report request!";
$pic1 = $_POST["pic1"];
$headers = "From: info#blablabla.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "
<html>
<head>
<title>New bug report request!</title>
</head>
<body>
<h1>New bug report request!</h1>
<hr>
<p>Name: asdfdasf<br>
Email: asdfasdf>
Website URL:asdfasdf<br>
Description: asdfasdf<br>
<img src=\"data:image/png;base64,$pic1\"/>
</p>
</body>
</html>
";
mail($to,$subject,$message,$headers);
At the moment I'm getting something like this:
Maybe I'm using wrong techniques to solve this, any help is welcome :-)
For people wanting to know how I fixed it:
I sent the Base64 image with an AsyncTask to my PHP script which decodes the string into an image, which is then stored on the server with as name a timestamp. After that, I get the right images and add them to a mail as an attachment using PHPMailer. Then I send the email and I get the pictures in a mail as attachment. Hope it can help some people!

HTML to send a pre-written email

I have put a website up on the internet, and I want to have a function where a user can enter their email address into a form and when submitted, they will receive a pre-set email.
There are other questions, but none of them seemed to help me.
I have basic code here:
<form action="send.php" method="post">
<input type="text" name="mail">
<input type="submit" value="send">
</form>
Here is the send.php
<?php
$mail = $_POST['mail'];
?>
<html>
<button>SEND</button>
</html>
Please excuse the fact that you have to press send twice, I will change that.
What I want to do, is send the user (email is represented by $mail) a pre written document via email, not as an attachment, but a the composition of the email.
I am unsure as to weather i can just use a word document, or there is complex code behind it.
Since i am only familiar with basic visual elements, please could you explain what parts of the code do what, as i may want to tweak it.
Thanks!
As Fred said, the best way to approach this is via PHP's mail function. When send.php runs, you can include PHP code like
mail($mail, "My Email Subject", "<html><b>Email Message</b></html>", $headers);
Where your header variable will have to contain all the necessary information to tell your client's mail software that the string message contains HTML that should be parsed. An example header setup is as follows, from CSS Trick's lovely example for this problem:
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Noting that you can replace the strip_tags call with whatever set emails you want. Then, you can replace my <html><b>Email Message</b></html> with whatever code you want to make a nicely formatted email.
Using PHP's mail() function also makes it so you do not need to click submit twice.

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.

PHP email style

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.

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