"Email a friend" script mod question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tattoo
Forum Newbie
Posts: 4
Joined: Thu Nov 13, 2008 3:34 pm

"Email a friend" script mod question

Post by tattoo »

Hello all, newbie question here.

I'm trying to modify a php "email a friend" script so that the email that's sent to the friend is in HTML format so I can include a picture.

I think I've isolated the pertinent part of the code to this:

function email($from, $from_name, $to, $message)
{
//header("Location: thankyou.html");return;

$headers .= "From: ".$from."\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";

$your_domian_name = "www.mydomain.com";
//edit what you want your vistors to see in their email here
$subject = $from_name." sent you an invitation to $your_domian_name";
$your_message = "Hello!\r\n";
$your_message.= ucfirst($from_name);
$your_message.= " wants you to check out $your_domian_name\r\n";
$your_message.= "Sender's Message:\n\r";
<a href="../mywebpage.html"><img src="myimage.jpg" alt="blahblah" width="144" height="69" border="0" /></a>


$message=$your_message.stripslashes($message);

if (mail($to,$subject,$message,$headers) ) {
return true;
} else {
return false;
}
I'm pretty sure that I must need to change the content type from text to HTML. How do I do that? Also, you see the href tag below the last $your_message. How do I correctly format that? And do I need to ad anything else to make it work?

Any help or direction on this will be MUCH appreciated. Cheers.
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: "Email a friend" script mod question

Post by Syntac »

Change the "Content-type: text/plain" part to "Content-type: text/html". Unless you've borked something else (which you haven't, as far as I can tell), it should work.

Also, one of your newlines is messed.
tattoo
Forum Newbie
Posts: 4
Joined: Thu Nov 13, 2008 3:34 pm

Re: "Email a friend" script mod question

Post by tattoo »

What is a "newline", and how is it messed up? And how do I incorporate the html "<a href, etc." into this script correctly?

Thank you
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: "Email a friend" script mod question

Post by Syntac »

A newline is a line break. CR, LF, CRLF, you know. \r, \n, and \r\n. In your script, you messed one up — it says \n\r instead of \r\n.
tattoo
Forum Newbie
Posts: 4
Joined: Thu Nov 13, 2008 3:34 pm

Re: "Email a friend" script mod question

Post by tattoo »

Oh - of course, I see. Thank you.

Now how and where do I insert the HTML for the outgoing email?

Cheers
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: "Email a friend" script mod question

Post by Syntac »

Just stick it in the message body.

Code: Select all

$your_message .= "<a href=\"../mywebpage.html\"><img src=\"myimage.jpg\" alt=\"blahblah\" width=\"144\" height=\"69\" border=\"0\" /></a>";
Obviously you'll have to change the paths to absolute URLs, but other than that, this should work fine.
tattoo
Forum Newbie
Posts: 4
Joined: Thu Nov 13, 2008 3:34 pm

Re: "Email a friend" script mod question

Post by tattoo »

Thank you SO much! I'm off to try.

Cheers
Post Reply