Print only link name not whole href in php mail body - php

When sending an email I want to show the hyperlink value not the whole href.
This is my code
if ($model->update(array('status')))
{
$body.="Your account has now been verified. Please, login and spiff up your profile and take a look at our ,";
$body.="<a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>";
$body.="to start building your business!";
$email=$model->email;
mail($email,$subject,$body,$headers);
//----------------------------------------------------------//
$this->redirect($model->user_id);
}
I want to send sponsored program not the whole href in the mail body. But whenever I send an email using this it prints <a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>"; instead of Sposorship Program
I have tried to add double quotes inside single quotes but it didn't work.

You need to add to headers:
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
if you haven't done it yet.
Also you have to make sure your e-mail client is properly set. For example in Mozilla Thunderbird you may set it to display only TXT and then it may perform some changes to the content. Otherwise you may send email correctly but you will result you don't expect

Based on http://php.net/manual/en/function.mail.php
You need to inform mail engine, that you are sending something more complicated then just text
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);

You are sending the mail as plain text, so html would not be recognized. Add these to the $headers:
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
See http://www.php.net/manual/en/function.mail.php

Related

How to send email to yahoo via PHP

I am attempting to send a confirmation email from a PHP script. I tested on gmail and it worked fine (the email was sent with appropriate subject and contents), however when I tried sending an email to a yahoo account, the subject field was correct but the contents were sent as an attachment as opposed to text inside the actual email. Here is the mailing code.
$headers = 'From: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= 'Reply-To: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= "BCC: orders#COMPANY_NAME.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text; charset=ISO-8859-1\r\n"
mail($email, "COMPANY_NAME Order Confirmation $confirmation_number", $text, $headers);
How can I send an email to yahoo that will include $text inside the email as opposed to an attachment?
It may be because of a wrong "Content-Type" header: I do not think "text" is a valid content type.You should try, instead, with "text/plain".
Content-Type: text/plain; charset=ISO-8859-1
PS: you may also want to consider using UTF-8 instead of ISO-8859-1.

PHP mail can not send when there is a url a tag in the body

When I added "a href tag " in the mail body the mail is not sent.
If I remove this 'a href and www' tag, the mail sends and all other content display as per my requirement.
I don't know where is the exact problem, I'm using GoDaddy hosting with PHP 5.3 version.
If anyone has a better solutions please share with me .
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<a href=www.google.com>Click here</a>';
// To send HTML `enter code here`mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
// Additional headers
$headers .= 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
Use this as the header:
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
that's if you want to use HTML in the body, but you have to create well formatted HTML, you know with all of its tags: html, head, body, and close them all.
<html>
<head></head>
<body>Content here and this is a link</body>
</html>
I had the same problem once, turned out my spam filter blocked the mail when a link was in it and let it trough when I removed the link.
Took me some time to notice that

HTML not formatting in mail function

I am using the following code:
$message = "Hi ".$user.
",\r\rThe following names are on the guestlist for <b>".$night.
"</b> on ".$date2.":\r\r". $user ."<br>". implode(", ", $names).
"\r\rThank you for using Guestvibe.";
mail($email, "Your Guestvibe list", $message);
The carriage returns in PHP are working fine, but neither the <b> or <br> tags are coming out. Is it just my mail client (Apple Mail) playing up, or is there a fix for this?
You are sending the e-mail as text only not HTML, I believe you need to set these headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
as in example #4 of the docs.
PHP's mail function sends plaintext mail by default.
See the nr.4 example at mail's manual page for the correct way to send HTML mail.
You need to add your headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($email, "Your Guestvibe list", $message, $headers);
You should firstly wrap the whole message into:
<html><head></head><body> msg </body></html>
Plus headers from m.edmondson post.

sending only a text email instead of html

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.

How to send HTML/CSS emails?

Most email clients have problems reading CSS in HTML emails (including Gmail and Hotmail). I often use this service to convert my HTML/CSS to proper email format so that everything looks normal on the user's end. Basically what it does is convert all CSS to inline styles:
http://premailer.dialect.ca/
Do any of you have any other methods for sending CSS in your HTML emails? I automatically generate the emails, and due to some restrictions, I can't modify the the inline styles.
As for direct format, I've always done inline CSS styling, however I use SwiftMailer (http://swiftmailer.org/) for PHP5 to handle email functionality and it has helped immensely.
You can send multipart messages with different formats so if the email client doesn't like the HTML version, you can always default to the text version so you know at least something is getting through clean.
In your "views" folder, you can set apart routes for different email formats (I use smarty too, hence the .tpl extension). Here's what a typical SwiftMailer::sendTemplate() function would look like when you're setting up the templates:
$email_templates = array('text/html' => 'email/html/' . $template . '.en.html.tpl',
'text/plain' => 'email/text/' . $template . '.en.txt.tpl');
foreach ($email_templates as $type => $file) {
if ($email->template_exists($file)) {
$message->attach(new Swift_Message_Part($email->fetch($file), $type));
} elseif ($type == 'text/plain') {
throw new Exception('Could not send email -- no text version was found');
}
}
You get the idea. SwiftMailer has a bunch of other good stuff, including returning "undeliverable" addresses, logging delivery errors, and throttling large email batches. I'd suggest you check it out.
You need to add a header that says the content is HTML. When you use the mail() function, one of the headers should be: Content Type: html/text (That might not be the 'exact' header).
Let me find you an example: (From the php.net/mail page)
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
To add to the above example, (in case you don't know PHP very well), you just have to build the "email" using the variables: to, subject, message, and headers
Let me know if you want to know how to create a form to fill and run this PHP script, otherwise, you can simply enter everything in this file manually, save as a PHP file, throw it up on a server that supports PHP, and navigate to the file in your browser.
Here's the code:
// Setup recipients
$to = 'johndoe#google.com' . ',' // comma separates multiple addresses
$to .= 'janedoe#msn.com';
// subject
$subject = 'PHP Email Script - Test Email';
// message (to use single quotes in the 'message' variable, supercede them with a back slash like this--> \'
$message = '
<html>
<head>
<title>PHP Email Script</title>
</head>
<body>
<p style="background: #ccc; width: 100%;">Test Email Script</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Send the email
mail($to, $subject, $message, $headers);
the easiest way is to write a html page with embedded css and push it through automated styling machine

Categories