Sending a link in an email - php

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";

Related

PHP mail() changing some characters to htmlentities?

My PHP mail() script changes the ! exclamation mark on some email clients such as hotmail to %21 when the ! is in a tag in the email body.
Here's my script
$to = "myemail#outlook.com";
$subject = "Password Reset";
$body = "Link 1
<br><br>
Without href: http://example.com/#!/page - regular text
";
$headers = "From: no-reply#example.com\r\n";
$headers .= "Reply-To: no-reply#example.com\r\n";
$headers .= "Return-Path: no-reply#example.com\r\n";
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
mail($to,$subject,$body,$headers);
So in the script above, the ! is changed to %21 only when it's a link, the regular text keeps it as /#!/instead of transforming it to /#%21/
How would I go about fixing this issue so it doesn't change to %21?
Some characters are encoded because they are not valid URLs. In your case URL code points are replaced with percent-encoded byte %.

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

PHP mail sends but sender is always "Apache <apache#hosting12"

In my mail client or gmail the sender is always apache#hosting12
Any way to fix this issue?
I have tried setting the headers like these with no success. Can sombody please help me?
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'$from'> \r\n";
$headers .= "Reply-To: <'$from'> \r\n";
$headers .= "Return-Path: <'$from'>\r\n";
$headers .= "X-Mailer: PHP \r\n";
or
$headers = "From: $from";
I found that answer on a french forum.
http://www.developpez.net/forums/d413965/php/outils/configuration-sendmail_path-sender/
You can add a 5th param to the mail function:
mail($mail_recipient, $subject, $message, $headers, '-f'.$mail_from);
Ths '-f' + mail_from force the system to send the email as the mail_from.
There are extra single quotes in your header. Try like this:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <$from> \r\n";
$headers .= "Reply-To: <$from> \r\n";
$headers .= "Return-Path: <$from>\r\n";
$headers .= "X-Mailer: PHP \r\n";
Also you can remove the unnecessary "Reply-To" and "Return-Path".
Please remove single quotation mark from around $from and use {$from}
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
or you can use following signatures to pass from
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
EDIT:
You also want to check sendmail_from setting in php.ini file.

Problem dynamically sending text message with PHP

I am trying to dynamically send text messages using a PHP script. PHP code:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$textbody=<<<_MESSAGE_
Some text
_MESSAGE_;
mail('myphonenumber#SMSgateway','subject',$textbody,$headers);
I did receive a text message, but it is a "photo message" or rather multimedia instead of text and I am unable to open the message. I have tried playing around with the encoding and $textbody="this text"; instead of *MESSAGE*.
a) How can I send a normal text message (not multimedia)?
b) Why can't I open it?
c) Is there a way for people to respond to the texts I send with text? When I sent myself a text from hotmail I was able to reply and I got the answer in my inbox. When I tried to put $header.= 'From: me <me#somedomain.com>' . "\r\n"; the email wouldn't send
(reason: 553 sorry, your mail was
administratively denied. (#5.7.1))
Thanks!
$sendTo = "test#test.com";
$subject = trim($_POST['subj']);
$headers = "From: ".$_POST['name']."<" . trim($_POST["email"]) .">\r\n";
$headers .= "Reply-To: " . trim($_POST["email"]) . "\r\n";
$headers .= "Return-path: " . trim($_POST["email"]);
$headers .= "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$message = strip_tags($_POST["messg"]);
if (#mail($sendTo, $subject, $message, $headers))
{ echo "sent successfully"; }
else
{ echo "Error ... Plz try again later" ; }
This code which I'm using to send emails
I worked before on SMS project so if you have any question about how to link with Getaway feel free to contact me

send mail by bbc not working

hay
i used this code
$to = "mial#live.com,mail#yahoo.com";
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo 'ok';
}
but see what is happend
every user see the full list of the users
alt text http://img694.imageshack.us/img694/1289/21811933.gif
Your call to mail is passing the $to as the to parameter meaning those emails will be be in the to header try passing an empty string instead. You are passing the info into the bcc header so the email should still get to them that way.
That is because you have put all the users in the "to" line. You are also passing them into the "bcc" line too so just doing this may help you but as far as I know you need at least one address in the to line (although this may not be the case). It'll look pretty strange for each person doing it that way though.
The best way to avoid these issues would be to send the email multiple times, once to each user. To modify your code example to do this, I'd do something like the following:
$toAddresses = array("mial#live.com", "mail#yahoo.com");
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
foreach ($toAddresses as $to) {
if(mail($to, $subject, $message, $headers)){
echo "OK - sent message to {$to}";
}
}
The easiest way is to take this Mail-Class of phpguru.org:
http://www.phpguru.org/static/htmlMimeMail5
There you can specify with setBcc() the addresses which should be "blind", it's pretty easy and works well. I use this class in every project.
Best Regards.

Categories