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.
Related
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!
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);
Ok before you guys laugh LOLZ --> I'm not sure if this is a GMAIL issue or something I'm doing wrong but im trying to insert an email for an activation link in the body of a message.
$body = "Or click on this link: Activate Your Account "
Ok the problem here is that my GMAIL account shows this: (which BTW is click-able and routes correctly)
Or click on this link: <a href="http://www.url.com/start/page.php?verify=true&id=f22645cff5ecfd4d3c115af5&activate=75845> Activate Your Account </a>
What am I missing here? Is this just a gmail issue? How can i Correct this?
I want it to show: Activate Your Account
Try closing the quote at the end of your URL.
The SO syntax highlighting even showed you the issue.
Wrong Syntax,
error hould have showed you whats happening,
Parse error: syntax error, unexpected T_STRING on line x...
2 . Send HTML mail, the Content-type header must be set to html
I made some changes and tested this, try this working script :
<?php
$body = 'Or click on this link: Activate Your Account ';
// To send HTML mail, the Content-type header must be set
$headers = 'From: webmaster#example.com' . "\r\n" .
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("to#gmail.com","Subject goes here",$body,$headers);
?>
PHP Mail
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
For sure you're missing a double quote here.
<a href="http://www.example.com/...5845>
This shall be instead written as:
<a href="http://www.example.com/...5845">
If you didn't set the headers, this works for me. Of course you need to set your own variables.
$sender_email = strip_tags($sender_email);
$subject = "=?UTF-8?B?".base64_encode(strip_tags($title))."?=";
$message = nl2br(strip_tags($message));
$headers = "From: ".$sender_email.' <'.$sender_email.'>'."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\r\n";
$headers .= "\tformat=flowed;\r\n";
$headers .= "\tcharset=\"utf-8\";\r\n";
$headers .= "\treply-type=original\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "Reply-To: ".$sender_email."\r\n";
$body = __('sendfriend:defaultmessage') . '<br /><br/>'.$link.'<br/><br />'.$message;
$mail = mail($recipients, $subject, $body, $headers);
Make sure to send the email as an HTML email.
$headers = "From: myEmail#example.com\r\n";
$headers .= "Content-Type: text/html\r\n";
mail(...$headers);
Add the $headers variable on the end of the mail function.
define headers in your mail function first
$headers = 'From: abc#example.com' . "\r\n" .
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I have this code at the top of my email php file which sends out emails
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from <$from>" . "\r\n";
$headers .= 'Cc: matt.e#posnation.com' . "\r\n";
$headers .= 'Bcc: posnation#gmail.com' . "\r\n";
I need to change this to just a plain text email ...what do i change. I was thinking the second line text/html to text/text but i wasnt sure
You want to change the "text/html" to "text/plain".
You can use text/plain
But if you enter html content the tags and all will be shown on the client though ...
But i'm sure there's an alternate way to support both text and html ...
Are you using the built in mail function or an external mail app like phpMailer?
You don't need to change anything.
Technically it should be "text/plain", but if you want, you can just as easily send an "HTML" email with no HTML tags and it will work just fine.
I want to format content of the mail to show the content in different line.
here is my message contetn.
bu the \n and \r is not working in this case. it just shows all the content in one line.
$message = 'Thank you for using . We really appreciate your business.'."\r\n".'If you are making your payment by mail, please make the check out to "blah blah" and send it to:'."\n".'blah blah '."\n".'blah blah'."\n".'San Gabriel, CA 91776'."\n".'Please see the attached invoice in PDF format for easy saving & printing purposes.';
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($_POST['add6'],$subject, $message, $headers);
how can i do that?
You're telling the email client the message is HTML, so the CR LF combination will be treated like any other whitespace.
To fix this, change the content type to show you are sending a plain text email
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;
Alternatively, turn your message into an HTML message - an easy way to do that in your case would be to run it through nl2br to turn the newlines into <br> tags
Yep you've got Content-Type: text/html, so the CR LF is being treated like whitespace. Either send it as Content-Type: text/plain or call nl2br on your contents.
Your content type is HTML so you should use br or p tags instead of line feeds
For \n to work it needs to be double quotes, not single. "\n" is the right thing, '\n' is wrong and will not work.