php mail function, how to avoid hyperlink in the message - php

I'm using the php mail function and I have no problem sending the emails, I recieve well the emails on Hotmail and Gmail. But, when I wrote a web address in the message Gmail doesn't accepts the email because it arrives with an hyperlink, even though i'm writing the address in this way: "www.something.com" and I'm using Content-Type: text/plain; on the header.
I've tried to use strip_tags() with the message, but the problem persist.
What can I do?

Please try the code as follow:
<?php
$to = "to_email addrss";
$subject = "Your Subject";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<a href='http://yourlink.com'>http://yourlink.com</a>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster#yoursite>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
May be you failed to add content-type:text/html ,while sending your email address. may be this is the reason your anchor link it not working.hope this will work.

Related

adding a hyperlink in a sms email

What I am trying to do is send a registration confirmation sms via email from my website. I have it working now but I want to make sure that people are putting in correct phone numbers and carrier data. When my message sends it will send the word link but its not clickable is there a way to make the link clickable?
Here is my code so far.
<?php
$to = $mobil.$carier;
$subject = 'Registration for'.$school .'Scholarships Page';
$message = "
<html>
<head>
<title>Registration Email</title>
</head>
<body>
<h1>Email Registration Confirmation</h1>
<p>Welcome".$first_name." ". $last_name."
<p>In order to finish your registration for the scholarship site you need a valid
text phone number.
<p>Please Click the link given to confirm your registration.</p>
<a href=\"http://scholarship_domain/scholarships/activate.php?id=".$active_mobil ."\">Link
</a>
<p>If you have problems please contact your counsellor at your school. </p>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <scholarships.gnspes.ca>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
What happens now is the message sends but the link is not clickable and only the words "link" show up in the message. I guess I could just make it a link that a person could copy and paste but I am wondering if there is a way to make it a true hyperlink?
Thanks for the help.
When sending an Email or SMS to a phone number the message is automatically changed into html on the phone. I was able to get a clickable link send to myself with the following code but I would suggest making the message that it sends a little bit shorter because this message has to be sent as a picture message. I sent it to myself using just 0000000000#vtevt.com and it worked but the message was too long to show all the info so I sent just the link part and it works.
<?php
$to = $mobil.$carier;
$subject = 'Registration for '.$school .' Scholarships Page';
$message = '
Email Registration Confirmation
Welcome '.$first_name.' '. $last_name.'
In order to finish your registration for the scholarship site you need a valid
text phone number.
Please Click the link given to confirm your registration.
http://scholarship_domain/scholarships/activate.php?id='.$active_mobil .'
If you have problems please contact your counsellor at your school.
';
$message = str_replace("\n.", "\n..", $message);
// Always set content-type when sending HTML email
//$headers = "MIME-Version: 1.0" . "\r\n";
//$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
//$headers .= 'From: <scholarships.gnspes.ca>' . "\r\n";
mail($to,$subject,$message);
?>
Also there is no need to send headers in a text message if that's where your sending it to. And the subject doesn't work in a text. It only shows the email or website that it was send from.

PHP Email Title Display

I am trying to figure out how I can change what shows up for my company when I send out php emails. Right now this shows up:
I don't want it to say newsletter, I want it to say my companies name. I don't have anything in my code that says newsletter, so I am unsure of why that is even displaying, unless it just naturally takes what comes before the # in the email address. newsletter#companyname.com
What can I change in my code, so it reads my company name in the area I showed in the image, similar to what Amazon does, minus the .com.
$to = $newsletter_email;
$subject = 'Thank you for subscribing to the Newsletter';
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Newsletter</title>
</head>
<body>
</body>
</html>
';
$from = "newsletter#companyname.com";
$Bcc = "newsletter-notification#companyname.com";
// 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: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
Try
$from = 'My Company <newsletter#companyname.com>';
I think the problem is the way Gmail is displaying the name of the person when it's not specified.
Check what's in your sendmail.ini and php.ini:
sendmail.ini
force_sender=<email>
php.ini
sendmail_from=<email>

php mail() function, from address not working properly

I have created a website and hosted on a free server from 000webhost. I am sending an activation email for the registered users.
code
$to = "$email1";
$subject = 'Account Activation';
$message = '<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="margin-left: 100px">
<h1 >Hello '.$username.'</h1>
<p >• This mail is for your account activation .</p></br>
<p>• Please click on the below link to get your account activated.</p></br>
<p>• Login with your username and password after activation.</p>
</div>
</body>';
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\n";
$headers .= 'From: <developer#mysite.com>' . "\n";
mail($to, $subject, $message, $headers);
echo "success";
The problem is that whenever I send mail with from address shown above, the mails are not sent. The problem lies in that one line where i use from address in headers because if use some other names such as 'name#example.com' (here example is some other name) the mails are sent. The problem comes whenever i use mail provided by my hosting server. Can anyone help please?
From PHP: mail() $additional_headers:
Multiple extra headers should be separated with a CRLF (\r\n)
So split headers with \r\n:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <developer#mysite.com>' . "\r\n";
Check your $to is working or not.
or check spam folder in the recipient's mail.
Otherwise all thing is ok.
Further clarification go func_mail_mail

HTML tags in php email [duplicate]

This question already has answers here:
PHP: Html send email in html format
(2 answers)
Closed 8 years ago.
I want to send email in php with some HTML.
In my email, it's giving me like,
Hello <strong>,</strong><br><br>
It's not basically parse HTML code. Instead of effect, it's printing html tags.
This is my email function:
mail("$user_email","ESubject","$message","From: Name");
Message variable:
$message = "Hello <strong>,</strong><br><br>
To verify your email and complete your registration please click on the link below: <br /><br />
<a href='<?=$link?>'>VERIFY ACCOUNT</a>";
You need to set the Content type : text/html on your header !
// 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";
and add it to your mail()
mail($to, $subject, $message, $headers); //<--- Like that.
Note:
If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.
Source : PHP.net
EDIT :
Just do it this way
$message = "Hello <strong>,</strong><br><br>
To verify your email and complete your registration please click on the link below: <br /><br />
<a href=$link>VERIFY ACCOUNT</a>";
For better understanding please refer below script:
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>Hello <strong>,</strong><br><br>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>

PHP mail function not working

I have a php script that sends an email. It looks like this:
<?php
// subject
$subject = "$first_name $last_name has sent you a message on The Red-line";
// message
$message = "<html>
<head>
<title>
The Red-line
</title>
</head>
<body>
<p>
Hi $war_first,
</p> <br />
<p>
$first_name $last_name has sent you a message on the Red-line. To view your message, please login to <a href='www.thered-line.com'>the Red-line.</a>
</p> <br />
<p>
Sincerely,
</p> <br />
<p>
The Red-line Operator
</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 .= "From: The Red-line messages#theredline.com \r\n";
$headers .= "To: $war_first $last_war <$war_mail>\r\n";
// Mail it
mail($war_mail, $subject, $message, $headers);
?>
When I was testing this out on the remote server, I used this script to send an email to my inbox at turbocapitalist1987#yahoo.com. I got the email but the "from" part doesn't work . Yahoo says that my email was sent from "the#yahoo.com"
Does anybody have a clue as to why this isn't working?
Thanks
For your From header, enclose the actual address with < >:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
This is the correct format to use when you have both a display name and an email address. I'm guessing Yahoo was interpreting the first word "The" as the entire email address, and provided a default (yahoo.com) for the domain.
The <> seems to be your problem, it should be:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
Secondly, on Unix/Linux, you must have a working MTA (i.e.: sendmail, postfix, etc.) configured on your server, either to relay mail directly, or through a Smart Host. If you're on Windows, you must have a SMTP server configured in php.ini.
I would recommend using pre-built PHP email library such as: http://swiftmailer.org/

Categories