5 Replies - 608 Views - Last Post: 02 October 2012 - 11:51 AM Rate Topic: -----

#1 clee06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 01-June 10

trouble with mail() function

Posted 02 October 2012 - 10:15 AM

Hey guys, how do I put a hyperlink in the body in the mail() function?

this is what I have so far..

$friend = $_POST['text_friend'];
$subject = $_POST['text_subject'];
$from = $_POST['text_from'];
$temp_text = $_POST['text_message'];
//$temp_text = "Hey <friend>, 
//                Please join us on October 30, 2012 for a Halloween Party. 
//                <a href="google.com">Click here for more details.</a>";

$new_string = str_replace("<friend>", $full_name, $temp_text);

//mail (to, subject, body, headers)
mail( $friend, $subject, $new_string, $from);


This post has been edited by clee06: 02 October 2012 - 10:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: trouble with mail() function

#2 clee06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 01-June 10

Re: trouble with mail() function

Posted 02 October 2012 - 10:33 AM

Never mind I think I got it.


$friend = $_POST['text_friend'];
$subject = $_POST['text_subject'];

$from = "MIME-Version: 1.0" . "\r\n";
$from .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$from .= $_POST['text_from'];


$temp_text = $_POST['text_message'];
//$temp_text = "Hey <friend>, 
//                Please join us on October 30, 2012 for a Halloween Party. 
//                <a href="google.com">Click here for more details.</a>";

$new_string = str_replace("<friend>", $full_name, $temp_text);


$new_string2 = "<html>
        <body>
        $new_string
        </body>
        </html>";



//mail (to, subject, body, headers)
mail( $friend, $subject, $new_string2, $from);


Was This Post Helpful? 0
  • +
  • -

#3 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: trouble with mail() function

Posted 02 October 2012 - 10:40 AM

As a warning, the code you're using here can be very dangerous to use, because you're using POST variables directly. I'm assuming that you're doing this just for the sake of learning, but just in case -- make sure you don't put this up on any site that others can access.
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: trouble with mail() function

Posted 02 October 2012 - 11:41 AM

View PostMina-no-Hime, on 02 October 2012 - 01:40 PM, said:

As a warning, the code you're using here can be very dangerous to use, because you're using POST variables directly. I'm assuming that you're doing this just for the sake of learning, but just in case -- make sure you don't put this up on any site that others can access.

To be more specific, you're code is vulnerable to header injections. Have a look at this tutorial for further clarification: Preventing PHP Mail(...) Header Injections

You could also try PHPMailer which has a lot more functionality than the built in mail function.

This post has been edited by codeprada: 02 October 2012 - 11:42 AM

Was This Post Helpful? 1
  • +
  • -

#5 clee06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 01-June 10

Re: trouble with mail() function

Posted 02 October 2012 - 11:41 AM

View PostMina-no-Hime, on 02 October 2012 - 10:40 AM, said:

As a warning, the code you're using here can be very dangerous to use, because you're using POST variables directly. I'm assuming that you're doing this just for the sake of learning, but just in case -- make sure you don't put this up on any site that others can access.

haha thanks for the warning, but I did took the precaution to write some dummy code first and then post it here. None of the variables nor values means anything. I just wrote something that looks believable to get my point across.

This post has been edited by clee06: 02 October 2012 - 11:42 AM

Was This Post Helpful? 0
  • +
  • -

#6 clee06  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 01-June 10

Re: trouble with mail() function

Posted 02 October 2012 - 11:51 AM

Sorry for double posting again, but how come the codes above does not work for Windows Live Mail? It worked correctly for my hotmail and gmail account..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1