assist with inserting a picture into an html email using php - php

Hello: been doing html emails with php mail() without any problems - but having a heck of time trying to add a picture properly. I load in the content of the email into a variable called $messageContent
here is my actual calling of the mail() function:
$headers = "From: BBT Admin - " . $emailFrom . "\r\n";
$headers .= "Reply-To: ". $emailFrom . "\r\n";
$headers .= "BCC: ".$bccEmail."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($emailTo,$subject,$messageContent,$headers);
All of this works fine - only have problems depending on what I put in the "content" variable...
I basically keep appending to the content variable - building the content one piece at a time...here is the part that is the problem:
$messageContent="";
$messageContent.="<a
href='http://www.example.com'>example.com</a>";
$messageContent.="<br style='clear:both;'/>";
$messageContent.="<br/><br/>";
$messageContent.="<img src='http://example.com/wp-content/uploads/2018/03/Capture_bbtmap3.png'/>";
So this doesnt work that well - so if anyone can help on this it would be greatly appreciated!

Related

HTML attributes missing in sending email

Sending mail inside wordpress admin. Headers:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
With From/Reply-to headers its didnt work;
In the <a> tag inside the letter all attrs( href, style ) is gone.
Message i get from $_REQUEST, textarea tag where href display correct.
IF i use a constant string as argument for mail, links work properly. Please help.
solved by myself.
textarea send text with escape symbols ( \" instead " ). After removing its work
Please compare second line .
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
Try replacing your second line with:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
This is taken from PHP.net.

Output mutiple attatchments with PHP mail [duplicate]

This question already has answers here:
Sending multiple attachment in an email using PHP
(2 answers)
Closed 7 years ago.
I wonder if anyone can help me? I have done a lot of research on outputting multiple attachments using PHP mail but I just cant quite get my upload form working correctly.
Background:
I have a form which allows you to upload multiple images. The form itself is fine and i have had working with one one image no problem. The form sends a e-mail with an attachment. The problem has arisen when trying to send multiple attachments.
I can only ever get it to send one.
I have a piece of code below which deals with going through the array of files and adding them to headers of the e-mail. (see Below)
$headers = "MIME-Version: 1.0\r\n";
$headers = "X-Mailer: PHP/" . phpversion()."\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=".md5('boundary1')."\r\n\r\n";
$headers .= "From: Sell My Rolex <info#sellmyrolex.today>\r\n";
$headers .= "--".md5('boundary1')."\r\n";
$headers .= "Content-Type: multipart/alternative; boundary=".md5('boundary2')."\r\n\r\n";
$headers .= "--".md5('boundary2')."\r\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n\r\n";
$headers .= $message."\r\n\r\n";
$x="0";
foreach($files as $file){
$handle = fopen($destination.$file, "r");
$content = fread($handle, filesize($destination.$file));
fclose($handle);
$attachment = chunk_split(base64_encode($content));
$headers .= "Content-Type:".$types[$x]."; ";
$headers .= "name=\"".$file."\"\r\n";
$headers .= "Content-Transfer-Encoding:base64\r\n";
$headers .= "Content-Disposition:attachment; ";
$headers .= "filename=\"".$file."\"\r\n";
$headers .= "X-Attachment-Id:".rand(1000,9000)."\r\n\r\n";
$headers .= $attachment."\n\n";
}
This it is sent out
$message = wordwrap($message, 70);
$mailSent = mail($to, $subject, $message, $headers);
However all i get in the e-mail above the main e-mail message is
Content-Type:image/png; name="image1.png"
Content-Transfer-Encoding:base64
Content-Disposition:attachment; filename="image1.png"
X-Attachment-Id:6299
--f2b57013356e3f84c2c6b1d9b77f95d2--Content-Type:image/png; name="cleanoffice.png"
Content-Transfer-Encoding:base64
Content-Disposition:attachment; filename="cleanoffice.png"
X-Attachment-Id:5833
Can anyone point me in the right direction? I know people may want to suggest using a library like PHPmailer rather than the basic php mail but i want to use php mail to get this complete.
Any help is much appreciated.
Thanks
You need to include multiple boundaries to mark different attachments. The following gives you a good example of how it would look like.
http://www.qcode.co.uk/post/70

php mail() - "From" header interrupts sending

I got a code like this:
$headers = '';
//$headers .= 'Reply-To: "site\'s name" <newsletter#example.com>'."\r\n";
//$headers .= 'From: "site\'s name" <newsletter#example.com>'."\r\n";
$headers .= 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=utf-8'."\r\n";
mail($_POST['email'], stripslashes($result['title']), $message, $headers);
As long as those two lines are commented out, it sends emails correctly. Otherwise - it just doesn't. Without giving any error or even notice. It worked (uncommented code) until yesterday and now it stopped. Any ideas, why would it happen? I cannot use Swift or anything like that, because it's not my project.
Edit: incorrect quoting, but that wasn't the problem.
Edit: damn, it was just server admins, they blocked all mails with headers from non-existing accounts. I just had to create such mailbox, and i started working back again...
You have an error on site's name try with correct quoting
$headers .= 'Reply-To: "site\'s name" <newsletter#example.com>'."\r\n";
$headers .= 'From: "site\'s name" <newsletter#example.com>'."\r\n";
You can add header as the code below. Remove unwanted single quotes and double quotes. Just simple write as below.
$headers = "From: site name <newsletter#example.com> \r\n";
$headers .= "Reply-To: site\'s name <newsletter#example.com> \r\n";
$headers .= "MIME-Version: 1.0\r\n";

HTML Emails Sending in Plain Text? (PHP)

Okay okay, I know there are a million of these threads, but I did my best to look through them and could not find one that actually solved the problem for me. Any help is greatly appreciated, as depending on the browser it either hides the whole thing or shows it in plain text.
Here's what I'm using:
$headers = 'From: coupons#madisoncoupons.com\r\n';
$headers .= 'Reply-To: coupons#madisoncoupons.com\r\n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=ISO-8859-1';
mail($email,$subject,$content,$headers);
$content starts and ends with html and body tags, with a style tag in the beginning of the body with some CSS in it.
You'll want to use the correct quotes. "\r\n" and '\r\n' are two completely different things.
Read up on how PHP handles strings if you're rusty.
as #tadman said above, you have to modify your headers to the following
$headers = 'From: coupons#madisoncoupons.com' ."\r\n";
$headers .= 'Reply-To: coupons#madisoncoupons.com' . "\r\n";
Use this
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <info#example.com>' . "\r\n";
mail($email,$subject,$content,$headers);

send html email using php deliver message as html code

iam sending html message contains table
when i recive message on gmail,hotmail,yahoo account it works fine but when receiving on other client
ie Microsoft outlook it resolve it as html code !!
here is my email headers
'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html;charset= UTF-8' . "\r\n" .
'From: me <me#client.com>'
I Always use this function ,and it helps
function sendHTMLemail($HTML,$from,$to,$subject,$fromname)
{
$headers = "From: ".$fromname." <".$from.">\r\n";
$headers.= "Reply-To: ".$fromname." <".$from.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$boundary = uniqid("HTMLEMAIL");
// First we be nice and send a non-html version of our email
$headers .= "Content-Type: multipart/alternative;".
"boundary = $boundary\r\n\r\n";
$headers .= "This is a MIME encoded message.\r\n\r\n";
$headers .= "--$boundary\r\n".
"Content-Type: text/plain; charset=ISO-8859-1\r\n".
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode(strip_tags($HTML)));
// Now we attach the HTML version
$headers .= "--$boundary\r\n".
"Content-Type: text/html; charset=ISO-8859-1\r\n".
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($HTML));
// And then send the email ....
mail($to,$subject,"",$headers);
}
I know this isn't an answer for your question, but I suggest using a mailing library, that will allow you to send mails much more easily, and supports features such as attachments, authentication, etc.
I recommend SwiftMailer which works great, is simple and well documented.

Categories