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!
Related
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
I have a page which is sending an HTML email with the following PHP code:
$message = $body;//Create message body
$sender = $sender;//Create sender
$to = $customer_email;//Set who the email is being sent to
$subject = 'Quote - '.$_SESSION['quote_number'];//Subject for email
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";//Content-type header for mail() PHP built-in function
$headers .= 'To: '.$to . "\r\n";//To header for mail()
$headers .= 'From: '.$sender . "\r\n";//From header for mail()
$mail = mail($to, $subject, $message, $headers);//Send Email
Here is the part of the body with the image:
<img src="some_img.gif" alt="Title" width="400" height="55" align="left"/>
Right now when the email is sent, the image is not automatically downloaded, you have to right click it and download it. Is there a solution to automatically download this image within the mail() PHP function? If not, what is the easiest way I could do it?
I have done some research on this already, I have already looked at over 4 articles, here are a few that did not make sense to me, so I have not used the code in them. They are also pretty outdated.
How to embed images in email
Embed images for use in email message using PHP?
I am not interested in really complex code, for me I cannot stand classes and things like that where I just plain don't understand them.
Here is what you need:
<img src="data:image/gif;base64,<BASE64_ENCODED_IMG>" alt="Title" width="400" height="55" align="left"/>
<BASE64_ENCODED_IMG> should be the result of encoding the source binary of some_img.gif into Base64
You can do it on the fly with PHP: base64_encode(file_get_contents('/path/to/some_img.gif'));
Or get it done by an online service such http://www.base64-image.de/ and copy&paste the results.
You can find further info regarding this in Embedding Base64 Images
Edit: This may be obvious but... it is not possible to force the mail client to display images. But some clients just avoid to download them, so in this case this is a valid workaround.
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.
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.
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.