#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    81

    Sending a link in email


    How can I include a link in a simple email. How should it be formated?


    $email="me@you.com";
    $message= "Thank you for your email. Click this link to go to my web site";

    mail($email, 'Thank you', $message, 'From:admin@you.com');
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,939
    Rep Power
    9647
    You have to send an HTML email then.

    You can try it yourself (look at the fourth example here) or use something else like PHPMailer.

    [edit] If you provide the URL raw, most email clients are smart enough to make it into a link automatically.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    81

    mixing PHP with HTML


    I have read up on sending HTML emails. Now I want to put some PHP in the email. Not sure how to mix the HTML and the PHP.

    Code:
    $email="me@you.com";
    $message = '
    <html>
    <head>
      <title>This is the title</title>
    </head>
    <body>
      <p>Here is my message!</p>
      <img src="http://mywebsite.com/picture.jpg" />
     // I want to print a variable here.
      print "Your favorite color is $favColor";
    
    </body>
    </html>
    ';
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: My form <me@you.com>\r\n";
    mail($email, 'Thank you', $message, $headers);
    
    ?>
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,939
    Rep Power
    9647
    You can't put PHP into HTML. Can't put it in an email either.

    Don't think about it as email - think about it as a string.
    PHP Code:
    $message '
    <html>
    <head>
      <title>This is the title</title>
    </head>
    <body>
      <p>Here is my message!</p>
      <img src="http://mywebsite.com/picture.jpg" />
      Your favorite color is ' 
    $favColor '

    </body>
    </html>
    '

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    81
    Thanks requinix you are always a great help!

    Comments on this post

    • requinix agrees : "always a great help"? what? since when!?

IMN logo majestic logo threadwatch logo seochat tools logo