Walkere 19 Junior Poster in Training

u know it is not gonna work if your server is not configured to send email without authorization.

better u login and fast!

That is true. The simple mail() function won't work if you need authentication in order to send e-mails.

However, most SMTP servers don't require any type of authentication. If anything, they just check to see that the origin of the message is from inside the network.

I've been able to use the mail() function perfectly fine on a free host (Frihost.com) and a paid host (ixwebhosting.com). Neither required SMTP authentication.

- Walkere

Walkere 19 Junior Poster in Training

I assume you mean e-mail the link to the person. If you want to e-mail the actual page, that's a little different...

The most basic way to do e-mail a message would be to use the mail() function.

mail() takes a few parameters

  • $to - the recipient's e-mail address
  • $subject - the subject line (no newline characters!)
  • $message - the body of the message
  • $headers - a list of headers, including "From: myemail@domain.com"

So, you can gather the appropriate information with a form. For example, you might include an "e-mail this" link on a page. The user enters a "To:" and "From:" address, and the message and subject are created by the script.

Here's an example of it in action, with some hard-coded variables...

$to = "your-email@domain.com";
$subject = "Hey!  Check out this cool site.";
$message = "I found this site at http://mysite.com.  Check it out!";
$headers = "From: my-email@domain.com";

mail($to, $subject, $message, $headers);

That's all there is to it. Now just have your script populate those variables with the form information and you're good to go.

For some more examples, go read about mail() on php.net.

Walkere 19 Junior Poster in Training

I used to use an old version of Dreamweaver (MX, I think) and do all my testing online. I tried to set up apache, php and mysql on my local windows machine, but I had a bit of trouble and just said the hell with it.

However, a month or two ago I wiped one of my machines clean and put Ubuntu Linux on it. Best choice I ever made.

Now I've got apache, mysql, and php installed on a local server. I use that for all script development/testing now. Installation was a cinch, btw - about five minutes with the package manager and a few minutes tweaking the config files was all it took to get everything up and running.

As for actual coding, I use Quanta Plus. I tried Notepad++ before on my Windows machine, and it was ok... but I like the fact that Quanta Plus has many of the project capabilities that Dreamweaver does. For example, I can edit a whole bunch of local files and then batch-upload the modified files to the server.

Best of all, it's free... good old Linux.

- Walkere

Walkere 19 Junior Poster in Training

edit - I tried wrapping the PHP code in <pre> tags and that did the trick, still trying to understand why it does not work without them.

As other people have pointed out, the reason this doesn't work without a <pre> tag is that HTML ignores normal whitespace characters.

The reason it does work with a <pre> tag is that that is what <pre> tags are designed for. The text inside of a <pre> tag will be displayed with all white space intact - in your case with a newline character.

As was suggested before, use a <br /> tag instead of an '\n' if you want to create a line break in your HTML output.

However, the '\n' still has a function and it is still doing something. If you view the HTML source for the output of your script, you should notice that the newline is observed.

So, if you're echo-ing large amounts of HTML, it can be a very good idea to include newline characters in there. That way your source code is still readable and not just one long jumbled line.

- Walkere

Walkere 19 Junior Poster in Training

If I understand correctly...

The php script works fine and you received the newsletter.
The newsletter is formatted properly with the HTML.

The problem is that the pictures aren't appearing when you read the newsletter in your e-mail.

If that's the case, then you're problem may be in the way you specify the source for your images. In the HTML, you've got a reference to one image as: "images/newsletter_01.gif"

This type of relative URL won't work in an e-mail. The browser is looking for the file "images/newsletter_01.gif" inside the folder that the e-mail script is executing.

If you replace all of your relative URLs for images with absolute URLs (i.e. "http://www.mydomain.com/images/newsletter_01.gif"), they should appear correctly.

If that's not the problem, also make sure that your e-mail reader isn't blocking the images. I know that gmail blocks images by default. Some other web-based e-mail readers probably do the same thing.

Good luck,
- Walkere

Walkere 19 Junior Poster in Training

... I'm not entirely sure why'd you write your own function when the built-in addslashes function works perfectly well.

Aye, I was wondering the same thing.

addslashes() is slightly different - it escapes a couple of extra characters (including '\' and NUL). However, these (especially \) need to be escaped anyway.

So, to fill in the original example...

$unedited = $_POST['content'];
$content = addslashes($unedited);

However, you might be looking to learn how to use preg_replace... so we'll go back to the original example.

You can use preg_replace() like Fungus did with str_replace - sending an array as the search and replacement parameters.

The problem with your example is that you're only presenting one thing for the replacement parameter - "\'".

In order to replace ' with \' and " with \" you need to do one of a few things - perform two preg_replaces (one for each replacement), use arrays within the preg_replace, or use a variable in the regex to print the quote based on what the search found. I'm not that good with regex, so I'm not sure if you can do that... but I think you can.

Anyhow, here's an example of how you could use arrays to perform the desired function with preg_replace.

$string = "\"You're not very wise,\" said the wise man.";

$string = preg_replace(array("/'/", '/"/'), array("\'", '\"'), $string);
echo $string;

That appears to escape both the single and double quotes just fine.

Good …

Venom Rush commented: For someone so new to the site you really helped out big time ;) +1
Walkere 19 Junior Poster in Training

i want to view image as tooltip of small image on mouseover on that so what is the code for that?using javascript how it can be done?

This does seem a bit out of place for the php forum... and I'm not sure what the code is to do it in Javascript.

However, you can do this with plain CSS.

Here's the basic premise:

You wrap the text you want to "mouse-over" in an anchor tag, without any href element. It helps to use a separate class of anchor tags, like "info".

You create a span element within that anchor tag. By default, the css for that span (a.info span) would be display:none.

When you mouse-over the anchor, you change the span's display to block (a.info:hover span {display:block}). You'd also want to give the span element a "position: relative" declaration, so that it appears on top of the text instead of running into the surrounding text.

Don't have a full tutorial handy, but that's the basic concept. It's pretty nifty when it's all done. Pure CSS, no Javascript required. It works fine with text, so I'd think that you could put an img tag inside the span tag and have it work just fine as well.

- Walkere